Opened 5 months ago

Last modified 3 months ago

#35529 assigned Cleanup/optimization

Have the template tag query_string support Mapping[str, Any] as an argument — at Version 1

Reported by: Sarah Boyce Owned by: nobody
Component: Template system Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Sarah Boyce)

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, consensus appears to want to update this to also support Mapping[str, Any]

  • tests/template_tests/syntax_tests/test_query_string.py

    a b class QueryStringTagTests(SimpleTestCase):  
    9393        )
    9494        self.assertEqual(output, "?a=2&b=2")
    9595
     96    @setup(
     97        {"query_string_dict": "{% query_string my_dict %}"}
     98    )
     99    def test_query_string_with_explicit_query_dict_and_no_request(self):
     100        context = {"my_dict": {"a": 1, "b": 2}}
     101        output = self.engine.render_to_string("query_string_dict", context)
     102        self.assertEqual(output, "?a=1&b=2")
     103
    96104    @setup({"query_string_no_request_no_query_dict": "{% query_string %}"})
    97105    def test_query_string_without_request_or_explicit_query_dict(self):
    98106        msg = "'Context' object has no attribute 'request'"

Note: I believe this is backwards compatible so not a release blocker

Change History (1)

comment:1 by Sarah Boyce, 5 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top