From 86a64781932fbd8c80e82eb76acd6f8b2e8b33db Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 19 May 2016 00:10:41 -0700 Subject: [PATCH] Add FAQ about sending messages from outside --- docs/cross-compat.rst | 8 ++++---- docs/faqs.rst | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/cross-compat.rst b/docs/cross-compat.rst index ab6541e..bfc73e5 100644 --- a/docs/cross-compat.rst +++ b/docs/cross-compat.rst @@ -1,8 +1,8 @@ Cross-Compatibility =================== -Channels is being released as both a third-party app for Django 1.8 and 1.9, -and being integrated into Django in 1.10. Both of these implementations are +Channels is being released as both a third-party app for Django 1.8 through 1.10, +and being integrated into Django in future. Both of these implementations will be very similar, and code for one will work on the other with minimal changes. The only difference between the two is the import paths. Mostly, where you @@ -19,8 +19,8 @@ Becomes:: from django.channels import Channel from django.channels.auth import channel_session_user -There are a few exceptions to this rule, where classes were moved to other parts -of Django in 1.10 that made more sense: +There are a few exceptions to this rule, where classes will be moved to other parts +of Django in that make more sense: * ``channels.tests.ChannelTestCase`` is found under ``django.test.channels.ChannelTestCase`` * ``channels.handler`` is moved to ``django.core.handlers.asgi`` diff --git a/docs/faqs.rst b/docs/faqs.rst index 08482c0..ec48c42 100755 --- a/docs/faqs.rst +++ b/docs/faqs.rst @@ -126,10 +126,31 @@ whatever you store in must be **network-transparent** - storing things in a global variable won't work outside of development. +How do I talk to Channels from my non-Django application? +--------------------------------------------------------- + +If you have an external server or script you want to talk to Channels, you have +a few choices: + +* If it's a Python program, and you've made an ``asgi.py`` file for your project + (see :doc:`deploying`), you can import the channel layer directly as + ``yourproject.asgi.channel_layer`` and call ``send()`` and ``receive_many()`` + on it directly. See the :doc:`ASGI spec ` for the API the channel layer + presents. + +* If you just need to send messages in when events happen, you can make a + management command that calls ``Channel("namehere").send({...})`` + so your external program can just call + ``manage.py send_custom_event`` (or similar) to send a message. Remember, you + can send onto channels from any code in your project. + +* If neither of these work, you'll have to communicate with Django over + HTTP, WebSocket, or another protocol that your project talks, as normal. + Are channels Python 2, 3 or 2+3? -------------------------------- -Django-channels and all of its dependencies are 2+3 (2.7, 3.4+). Compatibility may change with time. If in doubt, refer to the ``.travis.yml`` configuration file to see which Python versions that are included in CI testing. - -This includes Twisted, for which the used subsets of the library used by Daphne are all py3k ready. +Django-channels and all of its dependencies are compatible with Python 2.7, +3.3, and higher. This includes the parts of Twisted that some of the Channels +packages (like daphne) use.