我正在尝试将Python和Django设置为与Apache一起使用。
Django项目只给我一个空白页,所以我尝试了在许多地方找到的示例:
def application(environ, start_response):
status = '200 OK'
output = 'This is my Website!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
我在app.py文件的开头添加了以下几行:
#!C:/Program Files/Python34/python.exe
print('Content-Type: text/html')
print('\n\n')
我仍然得到空白页。
如果我添加以下代码:
def testFunction(text):
print(text)
testFunction('this works')
我得到了适当的输出(“行之有效”),所以我猜我的Python脚本正在运行。但是,如何获取可调用的应用程序(环境,start_response)?
我是Python / Django的新手,还是Apache的新手,所以我可能会遗漏一些琐碎的事情,但这是我尝试过的事情:
这是我的Apache配置文件中的部分:
WSGIScriptAlias /wsgi "C:/PythonWorkspace/app.py"
<Directory "C:/PythonWorkspace">
Options ExecCGI
AddHandler cgi-script .cgi .py
Require all granted
</Directory>
配置为:Windows Server 2008 / Apache 2.4 w MOD_WSGI / Python 3.4 / Django 1.6.5
预先感谢您的任何指点!
该代码由 CGI
print('Content-Type: text/html')
print('\n\n')
print('This is my Website!')
这是代码被使用 WSGI
def application(environ, start_response):
status = '200 OK'
output = 'This is my Website!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Apache配置为CGI
用于.py
文件
AddHandler cgi-script .cgi .py
要使用WSGI
你需要
AddHandler cgi-script .cgi # removed .py
AddHandler wsgi-script .py
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句