reverse
Returns a URL string by reversing a view name or reference against the URL configuration, optionally including query parameters and fragments. It resolves namespaces based on the provided application context and handles URL prefixing automatically.
def reverse(
viewname: string,
urlconf: string = None,
args: list = None,
kwargs: dict = None,
current_app: string = None,
query: dict = None,
fragment: string = None
) - > string
Returns the URL path for a given view name and arguments by performing a reverse lookup against the URL configuration.
Parameters
| Name | Type | Description |
|---|---|---|
| viewname | string | The name of the view or a namespaced path (e.g., 'app:view') to be resolved. |
| urlconf | string = None | The module path of the URL configuration to use for resolution; defaults to the root URLconf. |
| args | list = None | A list of positional arguments used to populate captured groups in the URL pattern. |
| kwargs | dict = None | A dictionary of keyword arguments used to populate named captured groups in the URL pattern. |
| current_app | string = None | The name of the application instance currently being processed to assist in resolving namespaced URLs. |
| query | dict = None | A dictionary or QueryDict of parameters to be URL-encoded and appended as a query string. |
| fragment | string = None | An optional string to be appended to the URL as a URI fragment (e.g., '#section-id'). |
Returns
| Type | Description |
|---|---|
string | The fully resolved URL path, including any optional query parameters and fragments. |