redirect
Return an HttpResponseRedirect to the appropriate URL for the arguments passed.
The arguments could be:
* A model: the model's `get_absolute_url()` function will be called.
* A view name, possibly with arguments: `urls.reverse()` will be used
to reverse-resolve the name.
* A URL, which will be used as-is for the redirect location.
Issues a temporary redirect by default. Set permanent=True to issue a
permanent redirect. Set preserve_request=True to instruct the user agent
to preserve the original HTTP method and body when following the redirect.
def redirect(
to: Union[Model, str, Callable],
*args: Any,
permanent: bool = False,
preserve_request: bool = False,
max_length: int = MAX_URL_REDIRECT_LENGTH,
**kwargs: Any
) - > HttpResponseRedirect
Return an HttpResponseRedirect to the appropriate URL for the arguments passed.
Parameters
| Name | Type | Description |
|---|---|---|
| to | Union[Model, str, Callable] | A model instance with get_absolute_url(), a view name, or a specific URL string to which the user should be redirected. |
| *args | Any | Positional arguments passed to the URL reverse resolution function. |
| permanent | bool = False | If True, returns an HttpResponsePermanentRedirect (HTTP 301) instead of a temporary redirect (HTTP 302). |
| preserve_request | bool = False | If True, instructs the user agent to maintain the original HTTP method and body when following the redirect (HTTP 307 or 308). |
| max_length | int = MAX_URL_REDIRECT_LENGTH | The maximum allowed length for the redirect URL to prevent URI-based attacks. |
| **kwargs | Any | Keyword arguments passed to the URL reverse resolution function. |
Returns
| Type | Description |
|---|---|
HttpResponseRedirect | An instance of HttpResponseRedirect or HttpResponsePermanentRedirect pointing to the resolved URL. |