When using Django Channels, in my routing.py, this works:
from django.conf.urls import url
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import my_app.routing
application = ProtocolTypeRouter({
'http': AuthMiddlewareStack(
URLRouter (
my_app.routing.http_urlpatterns +
[ url("", AsgiHandler) ]
)
)
})
But this doesn't:
from django.urls import path # <--- Changed
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import my_app.routing
application = ProtocolTypeRouter({
'http': AuthMiddlewareStack(
URLRouter (
my_app.routing.http_urlpatterns +
[ path("", AsgiHandler) ] # <--- Changed
)
)
})
When you run Django using path
, it runs, but if you try to load any pages, you get an exception like:
2021-02-05 09:42:10,420 ERROR Traceback (most recent call last):
File "/opt/my_proj/venv3/lib64/python3.6/site-packages/daphne/http_protocol.py", line "server": self.server_addr,
ValueError: No route found for path 'auth/login/'.
I'm using Django version 2.2.10 and channels version 2.3.0.
I was under the impression that url
was the old way, and path
was that new way, and even though their usage is slightly different, path
should be able to do anything url
can. Am I using it wrong? Or is this one place url
MUST be used?
In the documentation, even though all the examples seem to use url
, it does say:
question from:https://stackoverflow.com/questions/66066148/why-does-django-channels-asgihandler-not-work-with-path[URLRouter] Takes a single argument, a list of Django URL objects (either path() or url())