在Windows/Apache上设置Python? [英] Setting up Python on Windows/ Apache?
问题描述
我想获得一个简单的Python"hello world"网页脚本,以在Windows Vista/Apache上运行,但遇到了不同的问题.我正在使用WAMP.我已经安装了mod_python
并且模块显示了,但是我不确定我应该做什么例如http.conf(访问Add
I want to get a simple Python "hello world" web page script to run on Windows Vista/ Apache but hit different walls. I'm using WAMP. I've installed mod_python
and the module shows, but I'm not quite sure what I'm supposed to do in e.g. http.conf (things like AddHandler mod_python .py either bring me to a file not found, or a forbidden, or module not found errors when accessing http://localhost/myfolder/index.py). I can get mod_python.publisher
to work but do I "want" this/ need this?
任何人都可以帮忙吗?
谢谢!
推荐答案
远离mod_python
.一个常见的误导性想法是mod_python
类似于mod_php
,但适用于python.那是不对的. Wsgi 是运行python Web应用程序的标准,由 mod_wsgi
.
Stay away from mod_python
. One common misleading idea is that mod_python
is like mod_php
, but for python. That is not true. Wsgi is the standard to run python web applications, defined by PEP 333. So use mod_wsgi
instead.
或者,或者使用一些具有服务器的Web框架. Cherrypy 的特别好.您将能够独立运行应用程序,也可以通过mod_wsgi
运行该应用程序.
Or alternatively, use some web framework that has a server. Cherrypy's one is particulary good. You will be able to run your application both standalone and through mod_wsgi
.
使用cherrypy的Hello World应用程序示例:
An example of Hello World application using cherrypy:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
application = HelloWorld()
if __name__ == '__main__':
cherrypy.engine.start()
cherrypy.engine.block()
很容易吧?直接在python上运行此应用程序将启动Web服务器.配置mod_wsgi
使其可以在apache中运行.
Very easy huh? Running this application directly on python will start a webserver. Configuring mod_wsgi
to it will make it run inside apache.
这篇关于在Windows/Apache上设置Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!