是的你是對的,mod_python不能用於Python 2.7。所以mod_wsgi是你的最佳選擇。
我會推薦AMPPS作爲python環境默認情況下啓用mod_python和python 2.5。 AMPPS Website
,如果你仍想繼續,
加入這一行在httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
取消註釋httpd.conf中的行
Include conf/extra/httpd-vhosts.conf
打開虛擬主機文件的httpd的虛擬主機.conf並添加
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
<Directory "path/to/directory/in/which/wsgi_test.wsgi/is/present">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName 127.0.0.1
ServerAlias 127.0.0.1
WSGIScriptAlias /wsgi "path/to/wsgi_test.wsgi"
DocumentRoot "path/to/htdocs"
ErrorLog "path/to/log.err"
CustomLog "path/to/log.log" combined
</VirtualHost>
添加以下行wsgi_test.wsgi
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
注意:不要在htdocs目錄測試目錄。因爲我還沒有嘗試過。這些步驟在AMPPS中適用於我。 :)
然後在您最喜歡的瀏覽器中訪問127.0.0.1/wsgi。你會看到Hello World !.
如果你沒有看到,請按照QuickConfigurationGuide
OR
您可以在httpd.conf里加上這些行
<IfModule wsgi_module>
<Directory path/to/directory>
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
WSGIScriptAlias /wsgi path/to/wsgi_test.wsgi
</IfModule>
現在它給了我「錯誤500」或「錯誤403」:( – Bonny1992