Redirects
django_spire.core.redirect.generic_redirect
reverse_generic_relation
Source code in django_spire/core/redirect/generic_redirect.py
django_spire.core.redirect.safe_redirect
resolve_url
Resolves a URL name into its corresponding URL path using Django's reverse function.
Parameters:
-
url
(str
) –The URL name or URL string to resolve.
Returns:
-
str
–The reversed URL if successful; otherwise, the original URL.
Source code in django_spire/core/redirect/safe_redirect.py
is_url_valid_and_safe
Determines whether a URL is valid and safe by verifying that it has an allowed host and contains no harmful characters.
Parameters:
Returns:
-
bool
–True if the URL is valid and safe; False otherwise.
Source code in django_spire/core/redirect/safe_redirect.py
safe_redirect_url
Generates a safe redirect URL based on the request's GET parameters and HTTP_REFERER, ensuring that the URL is valid and safe. If neither the return URL nor the referer is valid, a fallback URL is returned.
Parameters:
-
request
(WSGIRequest
) –The WSGIRequest object containing GET and META data.
-
fallback
(str
, default:'/'
) –The fallback URL to use if no valid redirect URL is found; defaults to '/'.
Returns:
-
str
–A safe redirect URL.