URL Routing
- chanx.urls.path(route: Any, view: Any, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.urls.path(route: Any, view: URLRouter, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.urls.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
- chanx.urls.path(route: Any, view: Callable[[...], HttpResponseBase], kwargs: dict[str, Any] = None, name: str = '') URLPattern
- chanx.urls.path(route: Any, view: Callable[[...], Coroutine[Any, Any, HttpResponseBase]], kwargs: dict[str, Any] = None, name: str = '') URLPattern
Return a URLRouter or URLPattern for the specified route and view.
This function extends Django's url routing to support both Django views and ASGI applications/Channels consumers. 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 view to be called, which can be one of: - An ASGI application (Channels consumer) - A URLRouter instance (for nested routing) - A Django view function (synchronous or asynchronous)
kwargs -- Additional keyword arguments to pass to the view
name -- The name of the URL pattern for reverse URL matching
- Returns:
If the view is an ASGI application or a URLRouter URLPattern: If the view is a Django view function
- Return type:
URLRouter
- chanx.urls.re_path(route: Any, view: URLRouter, kwargs: dict[str, Any] = None, name: str = '') URLRouter
- chanx.urls.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
- chanx.urls.re_path(route: Any, view: Callable[[...], HttpResponseBase], kwargs: dict[str, Any] = None, name: str = '') URLPattern
- chanx.urls.re_path(route: Any, view: Callable[[...], Coroutine[Any, Any, HttpResponseBase]], kwargs: dict[str, Any] = None, name: str = '') URLPattern
- chanx.urls.re_path(route: Any, view: Any, kwargs: dict[str, Any] = None, name: str = '') URLResolver
- chanx.urls.re_path(route: Any, view: Sequence[URLResolver | str], kwargs: dict[str, Any] = None, name: str = '') URLResolver
Return a URLRouter, URLPattern, or URLResolver for the specified regex route and view.
This function extends Django's regex-based URL routing to support both Django views and ASGI applications/Channels consumers. It uses 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 view to be called, which can be one of: - An ASGI application (Channels consumer) - A URLRouter instance (for nested routing) - A Django view function (synchronous or asynchronous) - An included URL configuration - A sequence of URLResolvers or strings
kwargs -- Additional keyword arguments to pass to the view
name -- The name of the URL pattern for reverse URL matching
- Returns:
If the view is an ASGI application or a URLRouter URLPattern: If the view is a Django view function URLResolver: If the view is an included URL configuration or sequence
- Return type:
URLRouter