mirror of
https://github.com/django/daphne.git
synced 2025-07-13 09:22:17 +03:00
Add generics routing example
This commit is contained in:
parent
49c9b74d6f
commit
982a47a9df
|
@ -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
|
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.
|
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,
|
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
|
so it's safe to store things on ``self`` (in fact, ``self.message`` is the
|
||||||
current message by default).
|
current message by default).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user