Rai*_*ner 4 python apache mod-wsgi webapp2
我试图用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)
Run Code Online (Sandbox Code Playgroud)
当我将此文件保存为c:wamp\www\Python\hello.py,并浏览到localhost/Python/hello.py我得到:
Not Found
The requested URL /python/hello.py was not found on this server.
Run Code Online (Sandbox Code Playgroud)
但是,让我说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]
Run Code Online (Sandbox Code Playgroud)
位于c:\wamp\www\Python\test.py.当我去的时候localhost/Python/test.py,浏览器Hello from Python!就像我期望的那样说.
到目前为止,我只是通过放置行找到了如何将def(="application")的默认名称更改为"something_else"
WSGICallableObject something_else
Run Code Online (Sandbox Code Playgroud)
进入.htaccess.
但是,如何让Apache接受变量app作为可调用对象呢?(到目前为止,我主要使用Python进行网络外的编程,所以我希望这不是一个愚蠢的问题.)
任何帮助表示赞赏.
更新:
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>
Run Code Online (Sandbox Code Playgroud)
到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.
希望这有助于诊断......
从http://code.google.com/p/modwsgi/wiki/InstallationOnWindows安装mod_wsgi 并正确配置您的httpd.conf.
我假设你已经添加了这两行:
LoadModule wsgi_module modules/mod_wsgi.so
WSGICallableObject app
Run Code Online (Sandbox Code Playgroud)
从http://pypi.python.org/pypi/setuptools安装py-setuptools 然后为你的python安装模块
easy_install WebOb
easy_install Paste
easy_install webapp2
Run Code Online (Sandbox Code Playgroud)
创建虚拟主机
<VirtualHost *>
ServerAdmin admin@mydomain.com
DocumentRoot "/vhost/domains/mydomain/htdocs"
ServerName a.mydomain.net
WSGIScriptAlias / "/vhost/domains/mydomain/wsgi/main.py"
Alias /static/ "/vhost/domains/mydomain/htdocs/static/"
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
文件:main.py
import webapp2
class Hello(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
self.response.out.write('hello world!')
application = webapp2.WSGIApplication([
('/', Hello)
], debug=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3799 次 |
| 最近记录: |