Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight code examples #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ worker in two different threads, ``runworker`` to run separate workers,
and ``runwsserver`` to run a Twisted-based WebSocket server.

You should place consumers in either your ``views.py`` or a ``consumers.py``.
Here's an example of WebSocket consumers for basic chat::
Here's an example of WebSocket consumers for basic chat:

.. code-block:: python

import redis
from channels import Channel
Expand All @@ -56,9 +58,10 @@ Here's an example of WebSocket consumers for basic chat::
# you'd want expiring keys here in real life.

Alternately, you can just push some code outside of a normal view into a worker
thread::
thread:

.. code-block:: python


from django.shortcuts import render
from channels import Channel

Expand Down
8 changes: 6 additions & 2 deletions docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ How do we use channels?
-----------------------

That's what a channel is, but how is Django using them? Well, inside Django
you can connect a function to consume a channel, like so::
you can connect a function to consume a channel, like so:

.. code-block:: python

@Channel.consumer("channel-name")
def my_consumer(something, **kwargs):
Expand Down Expand Up @@ -99,7 +101,9 @@ message and can write out zero to many other channel messages.
Now, let's make a channel for requests (called ``django.wsgi.request``),
and a channel per client for responses (e.g. ``django.wsgi.respsonse.o4F2h2Fd``),
with the response channel a property (``send_channel``) of the request message.
Suddenly, a view is merely another example of a consumer::
Suddenly, a view is merely another example of a consumer:

.. code-block:: python

@Channel.consumer("django.wsgi.request")
def my_consumer(send_channel, **request_data):
Expand Down
4 changes: 3 additions & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Channels is available on PyPI - to install it, just run::
pip install -U channels

Once that's done, you should add ``channels`` to your
``INSTALLED_APPS`` setting::
``INSTALLED_APPS`` setting:

.. code-block:: python

INSTALLED_APPS = (
'django.contrib.auth',
Expand Down