Skip to main content

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

NameTypeDescription
viewnamestringThe name of the view or a namespaced path (e.g., 'app:view') to be resolved.
urlconfstring = NoneThe module path of the URL configuration to use for resolution; defaults to the root URLconf.
argslist = NoneA list of positional arguments used to populate captured groups in the URL pattern.
kwargsdict = NoneA dictionary of keyword arguments used to populate named captured groups in the URL pattern.
current_appstring = NoneThe name of the application instance currently being processed to assist in resolving namespaced URLs.
querydict = NoneA dictionary or QueryDict of parameters to be URL-encoded and appended as a query string.
fragmentstring = NoneAn optional string to be appended to the URL as a URI fragment (e.g., '#section-id').

Returns

TypeDescription
stringThe fully resolved URL path, including any optional query parameters and fragments.