Skip to content Skip to sidebar Skip to footer

Cannot Import Asgi_application Module While Runserver Using Channels 2

I have followed the channels tutorial but while running these error throw Version of the packages is channels==2.1.2 Django==2.0.4 what I missed ? in settings.py INSTALLED_APPS = [

Solution 1:

In my case it was wrong import in different file.

What you should do is

python manage.py shell
from mysite.routingimport application

Look what exact error it produces and try to fix that

Solution 2:

Just change

ASGI_APPLICATION = mysite.routing.application

to

ASGI_APPLICATION = "routing.application"

Solution 3:

Check for any potential errors (maybe import error) in consumers.py. Also, try to put channels as the first item in INSTALLED_APPS in settings.py.

As stated in channels document:

The Channels development server will conflict with any other third-party apps that require an overloaded or replacement runserver command. An example of such a conflict is with whitenoise.runserver_nostatic from whitenoise. In order to solve such issues, try moving channels to the top of your INSTALLED_APPS or remove the offending app altogether.

Solution 4:

You need to put your routing.py file inside mayapp/mayapp/routing.py instead of mayapp/routing.py

Solution 5:

In case anybody comes along this. Remember: ASGI_APPLICATION = "myapp.routing.application" should go at the bottom of settings.py to ensure nothing get snagged in production!

mysite/myapp/routing.py

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import myapp.routing

application = ProtocolTypeRouter({
    # (http->django views is added by default)'websocket': AuthMiddlewareStack(
        URLRouter(
            myapp.routing.websocket_urlpatterns
        )
    ),
})

myapp/routing.py

from django.urlsimport path
from . import consumers

websocket_urlpatterns = [
    path('chatroompage', consumers.ChatConsumer),
]

Post a Comment for "Cannot Import Asgi_application Module While Runserver Using Channels 2"