【问题标题】:how to set django setting path in docker container app?如何在 docker 容器应用程序中设置 django 设置路径?
【发布时间】:2022-01-02 21:10:27
【问题描述】:

我在 docker 容器内。并得到以下错误:

File "./source/asgi.py", line 14, in <module>
    from notifications.sockets import routing
  File "./notifications/sockets/routing.py", line 3, in <module>
    from . import consumers
  File "./notifications/sockets/consumers.py", line 7, in <module>
    from projects.models import Project
  File "./projects/models.py", line 6, in <module>
    User = get_user_model()
  File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 160, in get_user_model
    return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
  File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我的 asgi 文件代码在下面:

import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from notifications.sockets import routing

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

application = ProtocolTypeRouter({
  "http": get_asgi_application(),
  "websocket": AuthMiddlewareStack(
        URLRouter(
            routing.websocket_urlpatterns,
        )
    ),
})

我不明白这里出了什么问题..请帮我解决这个问题...谢谢。

【问题讨论】:

    标签: python django docker django-channels


    【解决方案1】:

    在这里回答 bc 我还不能发表评论,但是您能否在您的 settings.py 文件和您的 Dockerfile 中向我们提供 MIDDLEWARE 数组?

    这似乎是错误所在。您可能错过了在 settings.py 或 virtualenv 变量中包含 AuthMiddleware 或其他需要的中间件,或者 Docker 未正确加载这些变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 2011-01-30
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      相关资源
      最近更新 更多