生产中的 500 Internal Server Error - Django

500 Internal Server Error in production - Django

我是 django 的新手,我正处于项目的部署阶段。但是在所有设置之后,它显示 500 个内部服务器错误并且 apache2 错误日志显示 ImportError: No module named 'backend'

我尝试编辑 wsgi.py 因为我认为这是给出此错误的那个

这是我的 wsgi.py 文件的内容

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')

application = get_wsgi_application()

settings/dev.py

DEBUG = True
ALLOWED_HOSTS = ['my_ip_address']
WSGI_APPLICATION = 'backend.wsgi.application'

manage.py

import os
import sys

if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)

目录结构:

atms
 --backend
       --wsgi.py
       --urls.py
       --settings
            --dev.py
 --manage.py

点冻结:

cairocffi==0.9.0
CairoSVG==2.2.1
cffi==1.11.5
cssselect2==0.2.1
defusedxml==0.5.0
Django==2.1.5
django-countries==5.3.2
django-weasyprint==0.5.4
djangorestframework==3.9.1
gunicorn==19.9.0
html5lib==1.0.1
Pillow==5.4.1
pycparser==2.19
Pyphen==0.9.5
pytz==2018.9
six==1.12.0
tinycss2==0.6.1
WeasyPrint==44
webencodings==0.5.1
whitenoise==4.0

atms.conf 在 /etc/apache2/sites-avalible

        Alias /static /home/atms/atms/public/static
        <Directory /home/atms/atms/public/static>
                Require all granted
        </Directory>

        Alias /media /home/atms/atms/media
        <Directory /home/atms/atms/media>
                Require all granted
        </Directory>

        <Directory /home/atms/atms/backend>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIScriptAlias / /home/atms/atms/backend/wsgi.py
        WSGIDaemonProcess django_app python-path=/home/atms/atms/backend python-home=/home/atms/venv
        WSGIProcessGroup django_app

错误日志显示

ImportError: No module named 'backend'

您已将 backend 直接放在您的 python-path 上,这意味着它本身不是一个可导入的名称。您应该将父目录放在那里:

WSGIDaemonProcess django_app python-path=/home/atms/atms python-home=/home/atms/venv