Cannot import ASGI_APPLICATION module while runserver using channels 2

后端 未结 12 1086
孤独总比滥情好
孤独总比滥情好 2021-01-07 19:59

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<

12条回答
  •  [愿得一人]
    2021-01-07 20:58

    When importing your app with absolute path in myapp/routing make sure it is imported like:

    import myapp.routing

    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
            )
        ),
    })
    

    It may give you warning as error in PyCharm but you will have working Django channels. I reported it as bug to PyCharm. I hope no one else will spend 3-4 hours on it like me)

提交回复
热议问题