[英]DJANGO ModuleNotFound: INSTALLED_APPNAME during gunicorn wsgi deployment
I'm setting up a wsgi.py and DockerFile to deploy my django app in DigitalOcean, but I'm getting the following errors during deployment phase after successful build.我正在设置 wsgi.py 和 DockerFile 以在 DigitalOcean 中部署我的 django 应用程序,但是在成功构建后的部署阶段出现以下错误。
I have django apps created by manage.py startapp XXX
each named 'users' and 'documents'.我有由
manage.py startapp XXX
创建的 django 应用程序,每个应用程序名为“用户”和“文档”。 From the error trace, I think there is a problem with the path since it is not detecting the apps from my "INSTALLED_APPS" config.从错误跟踪来看,我认为路径存在问题,因为它没有从我的“INSTALLED_APPS”配置中检测到应用程序。
-07-31 05:49:23] File "/code/scraft-server/wsgi.py", line 14, in <module>
[2022-07-31 05:49:23] from configurations.wsgi import get_wsgi_application # noqa
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/site-packages/configurations/wsgi.py", line 8, in <module>
[2022-07-31 05:49:23] application = get_wsgi_application()
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[2022-07-31 05:49:23] django.setup(set_prefix=False)
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
[2022-07-31 05:49:23] apps.populate(settings.INSTALLED_APPS)
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
[2022-07-31 05:49:23] app_config = AppConfig.create(entry)
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 223, in create
[2022-07-31 05:49:23] import_module(entry)
[2022-07-31 05:49:23] File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
[2022-07-31 05:49:23] return _bootstrap._gcd_import(name[level:], package, level)
[2022-07-31 05:49:23] ModuleNotFoundError: No module named 'users'
monorepo
├── README.md
├── __init__.py
├── backend-server
│ ├── users //(created with startapp)
│ ├── documents //(created with startapp)
│ ├── config
│ │ ├── common.py
│ │ ├── local.py
│ │ ├── production.py
│ ├── ...
├── docker-compose.yml
├── manage.py
├── requirements.txt
├── users
├── urls.py
├── wait_for_postgres.py
└── wsgi.py
import os
from configurations.wsgi import get_wsgi_application # noqa
application = get_wsgi_application()
import os
from .common import Common
class Production(Common):
INSTALLED_APPS = (
# ...
# My apps
"users",
"document",
# etc
"corsheaders",
"gunicorn",
)
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
# all other configs are set inside config.common.py
FROM python:3.8
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE backend-server.config.production
ENV DJANGO_CONFIGURATION Production
# Allows docker to cache installed dependencies between builds
COPY ./requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Adds our application code to the image
WORKDIR /code/backend-server
COPY backend-server .
WORKDIR /code
EXPOSE 8000
# Run the production server
CMD newrelic-admin run-program gunicorn --bind localhost:$PORT --access-logfile - backend-server.wsgi:application
The problem here is that your project does not recognize your application which is the users.这里的问题是您的项目无法识别作为用户的应用程序。 please change your application to look like this.
请将您的应用程序更改为如下所示。
INSTALLED_APPS = [
'users.apps.UsersConfig',
'document.apps.DocumentConfig',
]
https://docs.djangoproject.com/en/4.0/ref/applications/ https://docs.djangoproject.com/en/4.0/ref/applications/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.