How to Get Current URL in Django ?

Published On: 18/07/2022 | Category: Django Python

Hi Dev,

In this tute, we will discuss python django get current url example. you will learn python django url parameters. I would like to show you django get current url in view. if you want to see example of python django get urls then you are a right place.

So, In this example to get a current path and domain, path and query string in request to get a absolute url from request.

Let's see bellow example python django get urls.

To Get the Current Path:
{{ request.path }}
Output
/home/
Current Path with Query String:
{{ request.get_full_path }}
Output
/home/?q=test
Get Domain, Path and Query String:
{{ request.build_absolute_uri }}
Output
http://127.0.0.1:8000/home/?q=test

I Hope It will help you....