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 os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from django.conf.urls import url
from my_app.consumers import MyCustomConsumer
os.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.