CommandError: You have not set ASGI_APPLICATION, which is needed to run the server.エラーを解決したい
Django ChannelsでできるリアルタイムWeb
こちらのサイトを参考にdjangoのchannelsを勉強しています。
サイトの通り、consumers.py, routing.py, settinsg.pyにコードを記述しpython manage.py runserver 8080を入力すると、「CommandError: You have not set ASGI_APPLICATION, which is needed to run the server.」というエラーが出ます。
そのため
「ASGI_APPLICATION = 'myapp.routing.application'」
をsettings.pyに記述しましたが、
「 raise ImproperlyConfigured("Cannot import ASGI_APPLICATION module %r" % path)
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'myapp.routing'」
というように'myapp.routing'をインポートできません。というエラーが出ます。
なぜこのようなエラーが出ているのか、どのように解決できるのか、
かなり初歩的な質問かと思いますが、どなたかお分かりになられる方ご教授お願いします。
発生している問題・エラーメッセージ
CommandError: You have not set ASGI_APPLICATION, which is needed to run the server.
該当のソースコード
consumers.py from django.http import HttpResponse from channels.handler import AsgiHandler def http_consumer(message): # Make standard HTTP response - access ASGI path attribute directly response = HttpResponse("Hello world! You asked for %s" % message.content['path']) # Encode that response into message format (ASGI) for chunk in AsgiHandler.encode_response(response): message.reply_channel.send(chunk)
settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'myapp', 'channels', ] ... CHANNEL_LAYERS = { "default": { "BACKEND": "asgiref.inmemory.ChannelLayer", "ROUTING": "myproject.routing.channel_routing", }, }
routing.py from channels.routing import route channel_routing = [ route("http.request", "myapp.consumers.http_consumer"), ]
. ├── db.sqlite3 ├── manage.py └── myapp ├── __init__.py ├── consumers.py ├── routing.py ├── settings.py ├── urls.py └── wsgi.py $ python manage.py runserver 8080
試したこと
エラーメッセージの通りASGI_APPLICATIONを追加しました。
ASGI_APPLICATION = 'myapp.routing.application'
補足情報(FW/ツールのバージョンなど)
amzonlinux Python 3.6.8 django 2.1.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。