diff --git a/channels/generic/base.py b/channels/generic/base.py index 73d97fc..b54d703 100644 --- a/channels/generic/base.py +++ b/channels/generic/base.py @@ -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 diff --git a/docs/generics.rst b/docs/generics.rst index 97c013a..7edda19 100644 --- a/docs/generics.rst +++ b/docs/generics.rst @@ -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 ` representing the + message the consumer was called for. +* ``self.kwargs``, keyword arguments from the :doc:`routing` + WebSockets ----------