Opened 16 hours ago
Last modified 107 minutes 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 (3)
comment:1 by , 3 hours 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 |
comment:2 by , 2 hours ago
Seems like we should do something here.
So for only when it's changed, because if nothing has changed, you would expect it to reload? I think I agree with that line of reasoning though I haven't spent any time thinking about possible use cases and edge cases.
comment:3 by , 107 minutes ago
{% querystring %}
Outputs the current query string verbatim. So if the query string is ?color=green, the output would be ?color=green.
I guess specifically, I did not expect the test template_tests.syntax_tests.test_querystring.QueryStringTagTests.test_querystring_empty_get_params
to now return "?"
instead of ""
. But perhaps there's no real advantage of keeping the url the same?
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