Routing
- chanx.routing.include(arg: URLRouter | str | ModuleType) URLRouter
Include router from another module for Channels routing.
Similar to Django's URL include function, but designed for Channels routing. This allows for modular organization of WebSocket routing configurations.
This function can handle: - A URLRouter instance (returned as-is) - A string path to a module with a 'router' attribute - A module object with a 'router' attribute
The 'router' attribute should be a URLRouter instance.
- Parameters:
arg -- Either a URLRouter instance, a string path to a module, or the module itself. For string paths or modules, they should have a 'router' attribute.
- Returns:
The URLRouter instance from the module.
- chanx.routing.path(route: Any, view: Any, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.routing.path(route: Any, view: URLRouter, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.routing.path(route: Any, view: Type[ASGI2Protocol] | Callable[[HTTPScope | WebSocketScope | LifespanScope, Callable[[], Awaitable[HTTPRequestEvent | HTTPDisconnectEvent | WebSocketConnectEvent | WebSocketReceiveEvent | WebSocketDisconnectEvent | LifespanStartupEvent | LifespanShutdownEvent]], Callable[[HTTPResponseStartEvent | HTTPResponseBodyEvent | HTTPResponseTrailersEvent | HTTPServerPushEvent | HTTPDisconnectEvent | WebSocketAcceptEvent | WebSocketSendEvent | WebSocketResponseStartEvent | WebSocketResponseBodyEvent | WebSocketCloseEvent | LifespanStartupCompleteEvent | LifespanStartupFailedEvent | LifespanShutdownCompleteEvent | LifespanShutdownFailedEvent], Awaitable[None]]], Awaitable[None]], kwargs: dict[str, Any] = None, name: str = '') URLRouter
Create a URLRouter for the specified route and ASGI application.
This function creates URLRouter instances specifically for Channels consumers and ASGI applications. It uses a simplified URL routing syntax with path converters similar to django.urls.path.
- Parameters:
route -- A string or promise that contains a URL pattern with optional path converters (e.g., '<int:id>/' or 'chat/<str:room_name>/')
view -- The ASGI application to be called, which can be one of: - A Channels consumer (WebSocketConsumer, AsyncConsumer, etc.) - A URLRouter instance (for nested routing) - An ASGI application
kwargs -- Additional keyword arguments to pass to the consumer
name -- The name of the URL pattern for reverse URL matching
- Returns:
A URLRouter instance wrapping the route and view
- Return type:
URLRouter
Note
This function is designed for WebSocket and ASGI routing only. For HTTP routing, use django.urls.path instead.
- chanx.routing.re_path(route: Any, view: URLRouter, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.routing.re_path(route: Any, view: Type[ASGI2Protocol] | Callable[[HTTPScope | WebSocketScope | LifespanScope, Callable[[], Awaitable[HTTPRequestEvent | HTTPDisconnectEvent | WebSocketConnectEvent | WebSocketReceiveEvent | WebSocketDisconnectEvent | LifespanStartupEvent | LifespanShutdownEvent]], Callable[[HTTPResponseStartEvent | HTTPResponseBodyEvent | HTTPResponseTrailersEvent | HTTPServerPushEvent | HTTPDisconnectEvent | WebSocketAcceptEvent | WebSocketSendEvent | WebSocketResponseStartEvent | WebSocketResponseBodyEvent | WebSocketCloseEvent | LifespanStartupCompleteEvent | LifespanStartupFailedEvent | LifespanShutdownCompleteEvent | LifespanShutdownFailedEvent], Awaitable[None]]], Awaitable[None]], kwargs: dict[str, Any] = None, name: str = '') URLRouter
Create a URLRouter for the specified regex route and ASGI application.
This function creates URLRouter instances specifically for Channels consumers and ASGI applications using regular expressions for more complex URL pattern matching.
- Parameters:
route -- A string or promise that contains a regular expression pattern (e.g., r'^ws/chat/(?P<room_name>w+)/$')
view -- The ASGI application to be called, which can be one of: - A Channels consumer (WebSocketConsumer, AsyncConsumer, etc.) - A URLRouter instance (for nested routing) - An ASGI application
kwargs -- Additional keyword arguments to pass to the consumer
name -- The name of the URL pattern for reverse URL matching
- Returns:
A URLRouter instance wrapping the route and view
- Return type:
URLRouter
Note
This function is designed for WebSocket and ASGI routing only. For HTTP routing, use django.urls.re_path instead.