mirror of
https://github.com/django/daphne.git
synced 2025-04-21 01:02:06 +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
|
||||
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).
|
||||
|
|
Loading…
Reference in New Issue
Block a user