Categories
Python Answers

How to get the current URL within a Python Django template?

Spread the love

Sometimes, we want to get the current URL within a Python Django template.

In this article, we’ll look at how to get the current URL within a Python Django template.

How to get the current URL within a Python Django template?

To get the current URL within a Python Django template, we can use request.path or request.get_full_path.

For instance, we write

{{ request.path }}  
{{ request.get_full_path }}  

in our template to render the URL without query parameters with request.path.

And we render the full URL with the query parameters with get_full_path.

Conclusion

To get the current URL within a Python Django template, we can use request.path or request.get_full_path.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *