separate http requests between channels routing and "classic django routing

35 views
Skip to first unread message

Kevin Tewouda

unread,
Mar 13, 2018, 2:48:11 PM3/13/18
to Django users
Hello,
i am developing an application (a REST one) which have to serve some sse events to a web application. I saw in the latest documentation how to create an SSE consumer, but now when i create an http routing for consumers, i can't serve the others requests using the "classic django view system". So my question is how can i separate the sse routing from the other http requests to have all of this working properly.
Thanks in advance for your suggestions.

Best regards

Andrew Godwin

unread,
Mar 14, 2018, 12:19:28 AM3/14/18
to django...@googlegroups.com
You can just use channels.http.AsgiHandler as the consumer/ASGI app to hand off to Django views. It's mentioned in the last paragraph here: http://channels.readthedocs.io/en/latest/topics/routing.html#protocoltyperouter

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6b19b58f-d5e3-4e31-908b-a9371e31b2cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Tewouda

unread,
Mar 14, 2018, 5:13:10 AM3/14/18
to Django users
Thanks Andrew
i found the mistake myself, my routing file was like this
http_urlpatterns = [
path('stream', ServerSentEventsConsumer),
path('', AsgiHandler)
]

I think that the second route will match all the default routes, but like it is mentionned in the tutorial, we have to use a regex path. So i change it to this and it works nice!

http_urlpatterns = [
path('stream', ServerSentEventsConsumer),
re_path(r'', AsgiHandler)
]

I think there should be a warning in the tutorial to take particular attention with the path method introduced in django 2.

Thanks again.


Le mercredi 14 mars 2018 05:19:28 UTC+1, Andrew Godwin a écrit :
You can just use channels.http.AsgiHandler as the consumer/ASGI app to hand off to Django views. It's mentioned in the last paragraph here: http://channels.readthedocs.io/en/latest/topics/routing.html#protocoltyperouter

Andrew
On Tue, Mar 13, 2018 at 9:20 AM, Kevin Tewouda <lewo...@gmail.com> wrote:
Hello,
i am developing an application (a REST one) which have to serve some sse events to a web application. I saw in the latest documentation how to create an SSE consumer, but now when i create an http routing for consumers, i can't serve the others requests using the "classic django view system". So my question is how can i separate the sse routing from the other http requests to have all of this working properly.
Thanks in advance for your suggestions.

Best regards

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andrew Godwin

unread,
Mar 14, 2018, 11:38:05 AM3/14/18
to django...@googlegroups.com
Ah, yes, there is a bug with URLRouter and path() where it will auto-add a $ to the regex it generates as it doesn't think the right-hand side is an include. This is likely something I need to patch in Django itself, but until then I suggest using re_path in any case where you want to match just a prefix.

Andrew

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages