Opened 13 hours ago
Last modified 87 seconds ago
#36182 new Bug
querystring templatetag should render empty querystring as "?" not "" when it has removed items from the querydict
Reported by: | David Feeley | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | 5.1 |
Severity: | Release blocker | Keywords: | querystring templatetag |
Cc: | David Feeley, Tom Carrick, Natalia Bidart | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
Consider 2 anchors that link to a filtered and unfiltered version of the current page via a GET param foo.
<a href="{% querystring foo=None %}">All Records</a> <a href="{% querystring foo=bar %}">Bar Records Only</a>
If the user is currently on the filtered page https://example.com/?foo=bar and clicks the first link, the querystring template tag, being empty, will render as "", which means href="" which the browser will interpret as reload the current (filtered) page. I believe instead the templatetag should render this case as "?"
https://github.com/dfeeley/django/compare/main..empty-querystring
thanks
Dave
Change History (1)
comment:1 by , 87 seconds ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Summary: | querystring templatetag should render empty querystring as "?" not "" → querystring templatetag should render empty querystring as "?" not "" when it has removed items from the querydict |
Triage Stage: | Unreviewed → Accepted |
Hi David, thank you for the ticket!
I think I agree with a slight caveat that I feel this should only be the case when the query dict has changed
A test and a very rough solution just to illustrate what I mean:
django/template/defaulttags.py
"tests/template_tests/syntax_tests/test_querystring.py
I am cc-ing some other folks to see what they think as well