Is it possible to pass query parameters via Django's {% url %} template tag?

Brian D picture Brian D · Jan 4, 2011 · Viewed 69.4k times · Source

I'd like to add request parameters to a {% url %} tag, like ?office=foobar.

Is this possible? I can't find anything on it.

Answer

Daniel Roseman picture Daniel Roseman · Jan 4, 2011

No, because the GET parameters are not part of the URL.

Simply add them to the end:

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

For Django 1.5+

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