Channel: Migrate regular Django project to Channels2

50 views
Skip to first unread message

Zhiyu (Drew) Li

unread,
Nov 7, 2018, 4:11:55 PM11/7/18
to django...@googlegroups.com
Hi there,

I am trying to migrate an existing Django project to Channels2. We want to keep all existing sync codes unchanged and we will continue mode of the development in sync mode. But having Channels opens the opportunity to develop some features in async mode.

I was able to install channels2 and get it configured. The portal still runs and all tests passed. But does it mean the migration is successful? How can I know if the tests were actually run in the channels2 env?

Anything particular I need to double check? like a migration checklist

Thanks
Drew

Andrew Godwin

unread,
Nov 7, 2018, 10:56:52 PM11/7/18
to django...@googlegroups.com
Channels doesn't take over at all unless you configure an async consumer. To make sure it's working I'd recommend writing a single async consumer, and running a test against that to ensure it works.

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...@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/CAMmsbU%3DzsYB5J7p4_mC1Gj3HqjiLRLo7Hc4UhaHEN_FXRv0ScA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Zhiyu/Drew Li

unread,
Nov 9, 2018, 4:11:21 PM11/9/18
to Django users
Thanks. 
I added a async http consumer from the doc. It kept throwing error on  "Header name 'Content-Type' expected to be `bytes`, but got `<class 'str'>`".
I was able to get it running after changing  to (b"Content-Type", b"text/plain"),

from channels.generic.http import AsyncHttpConsumer

class BasicHttpConsumer(AsyncHttpConsumer):
    async def handle(self, body):
        await asyncio.sleep(10)
        await self.send_response(200, b"Your response bytes", headers=[
            (b"Content-Type", b"text/plain"),
        ])
Reply all
Reply to author
Forward
0 new messages