To use django's build_absolute_uri()
function without including the query parameters, you can use the scheme
, netloc
, path
, and fragment
attributes of the HttpRequest
object to build the URL and then append any query parameters separately. Here's an example:
from django.http import HttpRequest
def my_view(request):
# Get the base URL
base_url = request.scheme + '://' + request.get_host() + request.path
# Append any fragment
url = base_url + '#section-1'
# Return the URL
return url
In this example, we first get the base URL by concatenating the scheme
, netloc
, and path
attributes of the HttpRequest
object. We then append any fragment
(e.g., #section-1
) to the URL separately. By not including any query parameters, we avoid using build_absolute_uri()
.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-03-15 11:00:00 +0000
Seen: 8 times
Last updated: Sep 12 '22
What is Fullscreen Activity in Android?
What does 'Invalid argument (callbackUrlScheme): must be a valid URL scheme' mean?
How can SSL passthrough be implemented with Traefik in Kubernetes?
What is authentication using C# ASP.NET Core MVC?
What are the steps to create a semi-circular shape divided into 8 parts using HTML, CSS, or SVG?
What is the way to name parameters and REST API urls in Spring Boot?
How can ASP.NET Core be configured to incorporate various authorization strategies?