Provide keyword args as self.kwargs in CBC (ref. #224)

This commit is contained in:
Andrew Godwin 2016-06-27 16:46:47 -07:00
parent 15aa962cd7
commit 5eb3bf848c
2 changed files with 10 additions and 1 deletions

View File

@ -26,6 +26,7 @@ class BaseConsumer(object):
the uninstantiated class, so calling it creates it)
"""
self.message = message
self.kwargs = kwargs
self.dispatch(message, **kwargs)
@classmethod

View File

@ -32,7 +32,8 @@ Here's a routing example::
Class-based consumers are instantiated once for each message they consume,
so it's safe to store things on ``self`` (in fact, ``self.message`` is the
current message by default).
current message by default, and ``self.kwargs`` are the keyword arguments
passed in from the routing).
Base
----
@ -62,6 +63,13 @@ If you want to perfom more complicated routing, you'll need to override the
remember, though, your channel names cannot change during runtime and must
always be the same for as long as your process runs.
``BaseConsumer`` and all other generic consumers than inherit from it provide
two instance variables on the class:
* ``self.message``, the :ref:`Message object <ref-message>` representing the
message the consumer was called for.
* ``self.kwargs``, keyword arguments from the :doc:`routing`
WebSockets
----------