Multi-valued query parameter and querystring

I’m trying to use Django’s querystring template tag in a template that has a query with multiple values for one parameter (?q=first&q=second…). Somehow the querystring tag only returns the first parameter and gobbles up the rest.

Some further info: when I display request.GET vs. querystring I get the followin:

<QueryDict: {‘q’: [‘HI_OB’, ‘HF_BFG’, ‘HF_BO’, ‘HI_PO’, ‘HI_FL’, ‘HI_SX’, ‘HI_SXJ’, ‘ASX’, ‘BFG’, ‘BSX’, ‘KTB’, ‘BF’, ‘HI_KTJ’], ‘title’: [‘Tuten und Blasen’]}>

?q=HI_KTJ&title=Tuten+und+Blasen

So it’s actually the last parameter that gets used in querystring instead of all.

See request.GET.getlist(‘q’)

I know about request.GET.getlist - this works as expected. The problem I experience is with the querystring tag not honoring all parameters (which, according to the docs it should).

If you’re using Django 6.0, a bug was reported for this wrong behaviour: see #36783 ({% querystring %} loses multi-value QueryDict in 6.0) – Django

This will be fixed in 6.0.1 : Django 6.0.1 release notes | Django documentation | Django

2 Likes

Thank you!

I just tested with that bugfix installed and everything works fine now.

Have a nice christmass!