在 Apache 中托管 Django

Hosting Django in Apache

提问人:Waly 提问时间:4/6/2020 更新时间:4/6/2020 访问量:28

问:

我尝试使用 mod_wsgi 在 Apache 上托管 Django 并遵循一个不错的教程。我有一个 Windows 7 OP,并且按照教程的描述设置了所有内容,但是,我收到此错误 500,我将 ErrorLogs 粘贴在下面:

[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] mod_wsgi (pid=7784): Failed to exec Python script file 'D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py'.
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] mod_wsgi (pid=7784): Exception occurred processing WSGI script 'D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py'.
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] Traceback (most recent call last):\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py", line 16, in <module>\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     application = get_wsgi_application()\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     django.setup(set_prefix=False)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 79, in __getattr__\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     self._setup(name)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 66, in _setup\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     self._wrapped = Settings(settings_module)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 157, in __init__\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\importlib\\__init__.py", line 126, in import_module\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374]   File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] ImportError: No module named 'weblog_app'\r

基本上,我不知道问题出在我使用的mod_wsgi版本还是我使用的配置中:

在这里,我复制了我用于 Apache 的 CONFIG

LoadModule wsgi_module "c:/users/adwy/appdata/local/programs/python/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIScriptAlias / "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py"
WSGIPythonHome "c:/users/adwy/appdata/local/programs/python/python35"
WSGIPythonPath "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app"

Alias "/static/" "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/static"
Alias "/templates/" "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/templates"


<Directory "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/static">
    Require all granted
</Directory>

<Directory "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/templates">
    Require all granted
</Directory>

<Directory "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app">
   <Files wsgi.py>
      Require all granted
   </Files>
</Directory>

任何有经验的人都可以帮助我吗?

多谢

python django apache mod-wsgi

评论

0赞 Gavin 4/6/2020
只是好奇,您是在使用新项目,还是尝试上传现有的开发项目,当我缺少依赖项时,我收到了此错误。
0赞 Waly 4/6/2020
我尝试按照构建博客项目的教程来学习..我没有上传任何项目,我从一开始就开始构建一切。你能解释一下吗?
0赞 Gavin 4/14/2020
好吧,可能导致此错误的一件事是,如果您的 django 项目没有安装正确的包。如果它列在 settings.py 中,则需要在服务器环境中安装和访问它。例如,如果使用像CrispyForms这样的插件,你需要确保它符合你的要求,然后确保它安装在服务器环境中。希望你能弄清楚

答: 暂无答案