separate http requests between channels routing and "classic django routing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

separate http requests between channels routing and "classic django routing

Kevin Tewouda
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: separate http requests between channels routing and "classic django routing

Andrew Godwin-3
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAFwN1urnqpo%2Bh122rkNLNBYA-o%3D35LWhvnHKx%2BRDYTdWROHt-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: separate http requests between channels routing and "classic django routing

Kevin Tewouda
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: <a href="http://channels.readthedocs.io/en/latest/topics/routing.html#protocoltyperouter" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Ftopics%2Frouting.html%23protocoltyperouter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdC6hVy37YbL67QgIzu5q0XePBEQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fchannels.readthedocs.io%2Fen%2Flatest%2Ftopics%2Frouting.html%23protocoltyperouter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdC6hVy37YbL67QgIzu5q0XePBEQ&#39;;return true;">http://channels.readthedocs.io/en/latest/topics/routing.html#protocoltyperouter

Andrew

On Tue, Mar 13, 2018 at 9:20 AM, Kevin Tewouda <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ReqAZXFEAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">lewo...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ReqAZXFEAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ReqAZXFEAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/6b19b58f-d5e3-4e31-908b-a9371e31b2cc%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/6b19b58f-d5e3-4e31-908b-a9371e31b2cc%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/6b19b58f-d5e3-4e31-908b-a9371e31b2cc%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/6b19b58f-d5e3-4e31-908b-a9371e31b2cc%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/7eaa6d7f-d088-4797-af61-dc6f3502136d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: separate http requests between channels routing and "classic django routing

Andrew Godwin-3
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

On Wed, Mar 14, 2018 at 2:13 AM, Kevin Tewouda <[hidden email]> wrote:
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 <[hidden email]> 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.
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/7eaa6d7f-d088-4797-af61-dc6f3502136d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAFwN1ur2AtqnEWiqPtDHU84qNyrvATZ2kUFzFpQDz5KBPKBurw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.