You need to route by URL - see the example in the docs here, including how
to fallback to Django views:
https://channels.readthedocs.io/en/latest/topics/routing.html#urlrouter

Andrew

On Tue, Oct 30, 2018 at 5:05 AM Zhiyu (Drew) Li <[email protected]> wrote:

> Thanks! Another question it seems once I manually put 'http':
> MyAsyncHttpConsumer pair in the ProtocolRouter, all existing sync http
> views stopped running as their type is "http" as well. So how to do a mix
> of async HTTP and sync http?
> Thanks
> Drew
>
> On Mon, Oct 29, 2018, 23:15 Andrew Godwin <[email protected]> wrote:
>
>> Yup, that's the right way - subclass the async consumer class and then
>> write a handle method. You have to do your own post/get distinctions, like
>> in a Django view, but with the scope rather than the request.
>>
>> Andrew
>>
>> On Mon, Oct 29, 2018 at 4:37 PM Zhiyu/Drew Li <[email protected]> wrote:
>>
>>> Not sure if this is the best way. I just found
>>> inside AsyncHttpConsumer.handle() I can access self.scope['method'] to
>>> determine if it is a GET or POST or others.
>>>
>>> Thanks
>>> Drew
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Monday, October 29, 2018 at 3:50:43 PM UTC-6, Zhiyu/Drew Li wrote:
>>>>
>>>> Hi there,
>>>>
>>>> Newbie to Channels.
>>>>
>>>> I am trying to write a Async consumer to handle a http GET request
>>>> How to write a subclass MyAsynHttpConsumer(AsyncHttpConsumer) for this
>>>> purpose? Or I am looking at the wrong class?
>>>>
>>>> Also if I understand correctly, I should manually add a new pair
>>>> 'http': MyAsynHttpConsumer to ProtocolTypeRouter()
>>>>
>>>> async_http_urlpatterns = [
>>>>     url(r'^async-http/$', consumers. MyAsynHttpConsumer   ),
>>>> ]
>>>>
>>>> ProtocolTypeRouter (
>>>> 'http': AuthMiddlewareStack(
>>>>         URLRouter(
>>>>              my_channels_app.routing.async_http_urlpatterns
>>>>         )
>>>>     ),
>>>> )
>>>>
>>>> Thanks
>>>> Drew
>>>>
>>>>
>>>>
>>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> 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/8c46871d-6e24-47e1-8813-5721014aedca%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/8c46871d-6e24-47e1-8813-5721014aedca%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/zQcvIvqapCo/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To post to this group, send email to [email protected].
>> 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/CAFwN1uopgpGn7uASW0%2BteonKN8qQFdBXcwA2N8_JM1-CTYiDdg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAFwN1uopgpGn7uASW0%2BteonKN8qQFdBXcwA2N8_JM1-CTYiDdg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CAMmsbUnQC-MFDHCV2Py1B_BajRRHDQJGjkOowSMBcNOULfTx%3DA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMmsbUnQC-MFDHCV2Py1B_BajRRHDQJGjkOowSMBcNOULfTx%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
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/CAFwN1uq0-9SusXtrQkw1GaN_Cv37QdA99-sGSo4Sg0vcccbhmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to