Apache下webapp2的(=无谷歌App引擎) [英] webapp2 under Apache (= without Google App Engine)
问题描述
我想对Python根据与Apache和mod_wsgi的运行webapp2的 - 具体为:Wampserver与Apache 2.2.22的Windows 7。到目前为止,我非常失败。 : - (
I am trying to run webapp2 under Python with Apache and mod_wsgi - specifically: Wampserver for Windows 7 with Apache 2.2.22. So far, I have failed miserably. :-(
我使用的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
,并浏览到本地主机/ Python的/ hello.py
我得到:
When I save this file as c:wamp\www\Python\hello.py
, and browse to localhost/Python/hello.py
I get:
Not Found
The requested URL /python/hello.py was not found on this server.
不过,我要指出的mod_wsgi的Python中的Apache似乎罚款运行;以下code
However, let me state that mod_wsgi for Python within Apache seems to be running fine; the following code
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
。当我去本地主机/ Python的/ test.py
,浏览器说你好Python的!
,因为我期望的那样。
is located at c:\wamp\www\Python\test.py
. When I go to localhost/Python/test.py
, the browser says Hello from Python!
as I would expect.
到目前为止,我只发现了如何通过将线以改变DEF的默认名称(=应用程序),以something_else
So far, I have only found out how to change the default name of the def (="application") to "something_else" by putting the line
WSGICallableObject something_else
到的.htaccess
。
但我怎么能得到阿帕奇接受变量应用
作为调用对象? (到目前为止,我已经使用Python的主要用于网络之外的节目,所以我希望这不是一个愚蠢的问题。)
But how can I get Apache to accept the variable app
as a callable object? (So far, I have used Python mainly for programming outside of the web, so I hope this is not a dumb question.)
任何帮助是AP preciated。
Any help is appreciated.
更新:
格雷厄姆问我。我正在使用Apache的配置文件的mod_wsgi配置,并在那里我加入吧。我加了
Graham asked me about the mod_wsgi configuration I am using in Apache configuration files and where I am adding it. I added
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行到底对不对。
to httpd.conf
right at the end of all the "LoadModule" lines.
这是我的配置一些额外的信息:我使用mod_wsgi-win32-ap22py27-3.3.so。 (当然,我把它重命名为 mod_wsgi.so
,并使其进入 C:\\ WAMP \\ BIN \\ apache的\\ apache2.2.22 \\模块$ 。C $ C>)我的Python命令行表示,这对版本:
的Python 2.7.3(默认情况下,2012年4月10日,23时31分26秒)MSC v.1500 32位(英特尔)]在Win
。我使用WAMP的服务器是32位。我的操作系统是Windows 7旗舰版64位SP1。
32
Some additional info on my configuration: I am using mod_wsgi-win32-ap22py27-3.3.so. (Of course I renamed it to mod_wsgi.so
and placed it into c:\wamp\bin\apache\apache2.2.22\modules
.) My Python command line says this about the version: Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
. The wamp server I am using is 32 bit. My operating system is Windows 7 Ultimate 64bit SP1.
希望这有助于诊断...
Hope this helps with the diagnosis...
推荐答案
从的 HTTP://$c$c.google.com/p/modwsgi/wiki/InstallationOnWindows 并正确配置你的httpd.conf
Install mod_wsgi from http://code.google.com/p/modwsgi/wiki/InstallationOnWindows and configure your httpd.conf properly.
我假设你已经添加了这些2号线:
I assume you have already added these 2 lines:
LoadModule wsgi_module modules/mod_wsgi.so
WSGICallableObject app
http://pypi.python.org/pypi/setuptools 安装PY-setuptools的然后安装模块为你的Python
Install py-setuptools from http://pypi.python.org/pypi/setuptools then install Modules for your python
easy_install WebOb
easy_install Paste
easy_install webapp2
创建虚拟主机
<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>
文件: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)
这篇关于Apache下webapp2的(=无谷歌App引擎)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!