django 没有找到Apache和mod_wsgi的模块[my_app]

c2e8gylq  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(101)

这是我的目录结构,在/var/www中:

team_django
--team_db
---- __init__.py
-----settings.py
-----wsgi.py

字符串
我的wsgi.py:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'team_db.settings')

application = get_wsgi_application()


我的/etc/apache2/mods-available/wsgi.load

LoadModule wsgi_module "/usr/local/py_ptracker/lib/python3.11/site-packages/mod_wsgi/server/mod_wsgi-py311.cpython-311-x86_64-linux-gnu.so"
WSGIPythonHome "/usr/local/py_ptracker"


我的/etc/apache2/sites-available/vhost.conf

<VirtualHost *:80>
    ServerName      mydomain
WSGIScriptAlias / /var/www/team_django/team_db/wsgi.py

<Directory /var/www/team_django/team_db>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>


启用了mod_wsgi,作为vhost配置,一切都加载得很好。我在error.log中得到了这个:

ModuleNotFoundError: No module named 'team_db'
 [wsgi:error] [pid 225277] mod_wsgi (pid=225277): Failed to exec Python script file '/var/www/team_django/team_db/wsgi.py'., referer: ...
[wsgi:error] [pid 225277] mod_wsgi (pid=225277): Exception occurred processing WSGI script '/var/www/team_django/team_db/wsgi.py'., referer: ....


为什么os.environ.setdefault找不到team_db?我已经检查了所有权限,我也将所有内容设置为777,将所有者和组更改为www-data或root等等;都没有用。我不明白为什么它找不到team_db. Te服务器与Django的runserver以及mod_wsgi-express runserver一起正确运行。
mod_wsgi是在虚拟环境中使用相同版本的Python构建的。

lrl1mhuk

lrl1mhuk1#

我不得不添加

from django.core.wsgi import get_wsgi_application

sys.path.append('/var/www/')
sys.path.append('/var/www/team_django')
sys.path.append('/var/www/team_django/team_db')```

to my .wsgi

字符串

相关问题