前提・実現したいこと
djangoのwebアプリをデプロイしたい。
発生している問題・エラーメッセージ
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
該当のソースコード
asgi.py
import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application import chat.routing import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') django.setup() application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack( URLRouter(chat.routing.websocket_urlpatterns) ) })
setting.py
ASGI_APPLICATION = 'mysite.asgi.application' CHANNEL_LAYERS = { 'default':{ 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [os.environ.get('REDIS_URL','redis://localhost:6379')], }, }, }
wsgi.py
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') application = get_wsgi_application()
あなたの回答
tips
プレビュー