73๐
โ
You can get full URL using request.build_absolute_uri
method:
FULL_URL_WITH_QUERY_STRING: request.build_absolute_uri()
FULL_URL: request.build_absolute_uri('?')
ABSOLUTE_ROOT: request.build_absolute_uri('/')[:-1].strip("/")
ABSOLUTE_ROOT_URL: request.build_absolute_uri('/').strip("/")
Should this will help full to you.
The best way to use ABSOLUTE URLS in Django, you can create a context_processors or middleware and find your ABSOLUTE_URL
and return that so that you can use any where in Django.
Like this example:
def absolute(request):
urls = {
'ABSOLUTE_ROOT': request.build_absolute_uri('/')[:-1].strip("/"),
'ABSOLUTE_ROOT_URL': request.build_absolute_uri('/').strip("/"),
}
return urls
And Then you should use {{ABSOLUTE_ROOT}}
in any where into you django template.
- [Django]-Count number of records by date in Django
- [Django]-How to update an object from edit form in Django?
- [Django]-Strange PostgreSQL "value too long for type character varying(500)"
-2๐
you can use
in template
{{ request.META.PATH_INFO }}
in views
end_point = request.META.get('PATH_INFO', None) # not recommend
please use David542โs answer
request.build_absolute_uri()
๐คC.K.
- [Django]-Django urls without a trailing slash do not redirect
- [Django]-Load a Django template tag library for all views by default
- [Django]-Django orm get latest for each group
Source:stackexchange.com