【发布时间】:2012-07-13 08:35:07
【问题描述】:
我正在尝试使用 Apache 和 mod_wsgi 在 Python 下运行 webapp2 - 特别是:Wampserver for Windows 7 with Apache 2.2.22。到目前为止,我失败得很惨。 :-(
我使用了来自https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingwebapp的以下示例:
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
当我将此文件保存为c:wamp\www\Python\hello.py,并浏览到localhost/Python/hello.py时,我得到:
Not Found
The requested URL /python/hello.py was not found on this server.
但是,让我声明一下,Apache 中用于 Python 的 mod_wsgi 似乎运行良好;以下代码
def application(environ, start_response):
status = '200 OK'
output = 'Hello from Python!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
位于c:\wamp\www\Python\test.py。当我转到localhost/Python/test.py 时,浏览器会按我的预期显示Hello from Python!。
到目前为止,我只发现了如何通过放置该行将 def (="application") 的默认名称更改为“something_else”
WSGICallableObject something_else
进入.htaccess。
但是如何让 Apache 接受变量 app 作为可调用对象? (到目前为止,我主要使用 Python 进行 Web 之外的编程,所以我希望这不是一个愚蠢的问题。)
感谢任何帮助。
更新:
Graham 询问了我在 Apache 配置文件中使用的 mod_wsgi 配置以及我在哪里添加它。我加了
LoadModule wsgi_module modules/mod_wsgi.so
<Directory "c:/wamp/www/python">
Options +ExecCGI
AddHandler wsgi-script .py
Order allow,deny
Allow from all
</Directory>
到httpd.conf 就在所有“LoadModule”行的末尾。
关于我的配置的一些附加信息:我正在使用 mod_wsgi-win32-ap22py27-3.3.so。 (当然我将它重命名为mod_wsgi.so 并将其放入c:\wamp\bin\apache\apache2.2.22\modules。)我的Python 命令行说明了这个版本:Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32。我使用的 wamp 服务器是 32 位的。我的操作系统是 Windows 7 Ultimate 64bit SP1。
希望这有助于诊断...
【问题讨论】:
标签: python apache mod-wsgi webapp2