Running my project with python manage.py runserver
boots it up perfectly using the channels asgi development server, however when running the project with Daphne (daphne project.routing:application
) I get the error AppRegistryNotReady: Apps aren't loaded yet
.
settings.py
INSTALLED_APPS = ['channels','whitenoise.runserver_nostatic','django.contrib.staticfiles','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.sites', # ... # ... installed apps and custom apps]WSGI_APPLICATION = 'project.wsgi.application'ASGI_APPLICATION = 'project.routing.application'CHANNEL_LAYERS = {'default': {'BACKEND': 'channels_redis.core.RedisChannelLayer','CONFIG': {"hosts": [REDIS_URL], } },}
routing.py
import osfrom channels.auth import AuthMiddlewareStackfrom channels.routing import ProtocolTypeRouter, URLRouterfrom django.core.asgi import get_asgi_applicationfrom django.conf.urls import urlfrom my_app.consumers import MyCustomConsumeros.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")application = ProtocolTypeRouter({"http": get_asgi_application(),'websocket': AuthMiddlewareStack( URLRouter([ url(r'^ws/custom/$', MyCustomConsumer), ]) ),})
I have tried adding django.setup()
as described in other questions, as well as running with uvicorn
instead of daphne
but still getting the same error. I've also tried pointing to the websocket routing in settings.CHANNEL_LAYERS['ROUTING']
and moving the application initialization out to an asgi.py
file but no luck there either. I can't tell what I'm doing differently from the channels documentation, any help appreciated.