我正在尝试使用mod_wsgi和WAMP部署基于Django rest-framework构建的API。当我使用'django-admin startproject Predictor'创建一个新的Django项目并将其部署在WAMP上时,它运行良好,因为我可以看到默认的Django窗口。
现在,我使用“ python manage.py startapp Predictor”在项目中创建了一个应用程序,我构建了一个接受GET调用的API,并使用“ python manage.py runserver”对其进行了测试,并且工作正常。现在,我再次启动了WAMP服务,并尝试转到“ localhost:8000”,它将继续加载。而且,一旦我停止WAMP服务,它就会崩溃,提示无法连接。不知道发生了什么。有人可以帮我做什么吗?仅供参考,我在Windows上,并且已经为Django项目创建了虚拟环境。这就是我的.conf和wsgi文件的样子
wsgi_windows.py
activate_this = 'C:/Users/DELL/Envs/predenv/Scripts/activate_this.py'
# execfile(activate_this, dict(__file__=activate_this))
exec(open(activate_this).read(),dict(__file__=activate_this))
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('C:/Users/DELL/Envs/predenv/Lib/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('C:/Users/DELL/Envs/predenv')
sys.path.append('C:/Users/DELL/Envs/predenv/Predictor')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Predictor.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Predictor.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd.conf
Listen localhost:8000
Listen [::0]:80
ServerName localhost:8000
LoadFile "c:/python376/python37.dll"
LoadModule wsgi_module "c:/python376/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/python376"
WSGIPythonPath "C:/Users/DELL/Envs/predenv/Predictor"
httpd-vhosts.conf
WSGIPythonPath "C:/Users/DELL/Envs/predenv/Predictor"
<VirtualHost *:80>
WSGIPassAuthorization On
ErrorLog "logs/predictor.error.log"
CustomLog "logs/predictor.access.log" combined
DocumentRoot "C:/Users/DELL/Envs/predenv/Predictor"
WSGIScriptAlias / "C:\Users\DELL\Envs\predenv\Predictor\Predictor\wsgi_windows.py"
<Directory "C:\Users\DELL\Envs\predenv\Predictor\Predictor">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
问题是在我看来,它无法“导入熊猫”。
要解决此问题,我必须在我的apache'httpd-vhosts.conf'文件中添加此行
WSGIApplicationGroup %{GLOBAL}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句