You can get the full url using the 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("/")
If it helps you.
The best way to use ABSOLUTE URLs in Django, you can create context_processors or middleware and find your ABSOLUTE_URL and return it so you can use any place 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}} anywhere in your django template.
source share