我正在尝试使用python构建Django应用进行练习,之后我想将其部署到本地Wamp服务器。 我设法安装了mod_wsgi模块,但是在最终配置中发现了一些问题,主要是因为使用Windows时,大多数指南和教程都是针对Ubuntu的。
Apache httpd.conf文件包含:
LoadFile "c:/program files (x86)/microsoft visual studio/shared/python37_64/python37.dll"
LoadModule wsgi_module "c:/program files (x86)/microsoft visual studio/shared/python37_64/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/program files (x86)/microsoft visual studio/shared/python37_64"
WSGIScriptAlias / "C:/wamp64/www/provaDjangoApp2/provaDjangoApp2/wsgi.py"
WSGIPythonPath "C:/wamp64/www/provaDjangoApp2/provaDjangoApp2;C:/wamp64/www/provaDjangoApp2"
<Directory "C:/wamp64/www/provaDjangoApp2/provaDjangoApp2">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Apache httpd-vhosts包含:
<VirtualHost *:80>
ServerName localhost
WSGIPassAuthorization On
WSGIScriptAlias / "C:/wamp64/www/provaDjangoApp2/provaDjangoApp2/wsgi.py"
<Directory "C:/wamp64/www/provaDjangoApp2/provaDjangoApp2">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/wamp64/www/provaDjangoApp2/static"
<Directory "C:/wamp64/www/provaDjangoApp2/static">
Require all granted
</Directory>
</VirtualHost>
这是我的Django应用中的wsgi.py文件:
import os
import sys
import site
# Add the app's directory to the PYTHONPATH
sys.path.append('C:/wamp64/www/provaDjangoApp2')
sys.path.append('C:/wamp64/www/provaDjangoApp2/provaDjangoApp2')
os.environ['DJANGO_SETTINGS_MODULE'] = 'provaDjangoApp2.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "provaDjangoApp2.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我实际上不知道这些配置是否可以,但是当我打开本地主机时,显示“ 500 Internal Server Error”错误。