gpt4 book ai didi

django - 生产中的 500 Internal Server Error - Django

转载 作者:行者123 更新时间:2023-12-05 05:09:53 27 4
gpt4 key购买 nike

我是 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()

设置/dev.py

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

管理.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

/etc/apache2/sites-avalible 中的 atms.conf

        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 路径上,这意味着它本身不是一个可导入的名称。您应该将父目录放在那里:

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

关于django - 生产中的 500 Internal Server Error - Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57128076/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com