#35529: Have the template tag query_string support Mapping[str, Any] as an argument
-------------------------------------------+------------------------
Reporter: Sarah Boyce | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 5.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Based off this discussion:
https://forum.djangoproject.com/t/adding-a
-template-tag-to-generate-query-strings/24521/28
Currenty `query_string` only supports a `QueryDict` as an argument.
{{{#!diff
--- a/tests/template_tests/syntax_tests/test_query_string.py
+++ b/tests/template_tests/syntax_tests/test_query_string.py
@@ -93,6 +93,14 @@ class QueryStringTagTests(SimpleTestCase):
)
self.assertEqual(output, "?a=2&b=2")
+ @setup(
+ {"query_string_dict": "{% query_string my_dict %}"}
+ )
+ def test_query_string_with_explicit_query_dict_and_no_request(self):
+ context = {"my_dict": {"a": 1, "b": 2}}
+ output = self.engine.render_to_string("query_string_dict",
context)
+ self.assertEqual(output, "?a=1&b=2")
+
@setup({"query_string_no_request_no_query_dict": "{% query_string
%}"})
def test_query_string_without_request_or_explicit_query_dict(self):
msg = "'Context' object has no attribute 'request'"
}}}
Note: I believe this is backwards compatible so not a release blocker
--
Ticket URL: <
https://code.djangoproject.com/ticket/35529>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.