Categories
Python Answers

How to pass query parameters via Python Django’s {% url %} template tag?

Spread the love

Sometimes, we want to pass query parameters via Python Django’s {% url %} template tag.

In this article, we’ll look at how to pass query parameters via Python Django’s {% url %} template tag.

How to pass query parameters via Python Django’s {% url %} template tag?

To pass query parameters via Python Django’s {% url %} template tag, we just append it after the URL.

For instance, in our template, we write

<a href="{% url 'myview' %}?office=foobar">
  ...
</a>

to add ?office=foobar after the URL for the myview view.

Conclusion

To pass query parameters via Python Django’s {% url %} template tag, we just append it after the URL.

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 *