From 982a47a9df7350f7d275ea631cf21ab3406cbfbe Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 25 May 2016 17:56:06 -0700 Subject: [PATCH] Add generics routing example --- docs/generics.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/generics.rst b/docs/generics.rst index 064e31c..0c969d3 100644 --- a/docs/generics.rst +++ b/docs/generics.rst @@ -21,6 +21,15 @@ to use ``route_class`` rather than ``route``; ``route_class`` knows how to talk to the class-based consumer and extract the list of channels it needs to listen on from it directly, rather than making you pass it in explicitly. +Here's a routing example:: + + from channels import route, route_class + + channel_routing = [ + route_class(consumers.ChatServer, path=r"^/chat/"), + route("websocket.connect", consumers.ws_connect, path=r"^/$"), + ] + 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).