Cannot import ASGI_APPLICATION module while runserver using channels 2

后端 未结 12 1029
孤独总比滥情好
孤独总比滥情好 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:33

    I was also having the same issue i did everything to resolve it, creating another virtual environment and installing older version of Django but after 2 days of hardware i came to realize that my consumers.py file was missing with just a 's' in consumer's' and after that i also corrected in my routing.py file. May be this could be your problem also please do check all the file names first.

    0 讨论(0)
  • 2021-01-07 20:36

    In my case it was wrong import in different file.

    What you should do is

    python manage.py shell
    from mysite.routing import application
    

    Look what exact error it produces and try to fix that

    0 讨论(0)
  • 2021-01-07 20:37

    Just change

    ASGI_APPLICATION = mysite.routing.application

    to

    ASGI_APPLICATION = "routing.application"

    0 讨论(0)
  • 2021-01-07 20:37

    I solved my problem by:

    • python manage.py migrate
    • python manage.py makemigrations
    • python manage.py migrate

    Also check if you have put the routing.py file in the wrong directory. It should be 'myproject/routing.py'

    0 讨论(0)
  • 2021-01-07 20:39

    I am also facing the same problem.
    Make sure:
    => The routing.py file should be inside the project root folder(i.e. django server, one that has settings.py, wsgi.py,..)
    => In settings.py include, ASGI_APPLICATION = "yourprojectrootname.routing.application"

    =>Sometimes, the coding inside routing.py file may generate this error, to check if this is the case remove all the coding and enter the general template coding,

    from channels.routing import ProtocolTypeRouter
    
    application = ProtocolTypeRouter({
        # Empty for now (http->django views is added by default)
    })
    

    then run the 'python manage.py runserver'. This time if you didn't get any error then problem lies in coding inside routing.py. Debug and fix the issue.

    =>In other cases this may be of version problem, downgrading to channels==2.1.2 works

    0 讨论(0)
  • 2021-01-07 20:41

    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.

    0 讨论(0)
提交回复
热议问题