summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGiannis Terzopoulos <terzo.giannis@gmail.com>2025-03-19 12:21:41 +0100
committernessita <124304+nessita@users.noreply.github.com>2025-03-25 12:23:41 -0300
commita39c28706aa7a8c3effd0980ae6d59ae67299d85 (patch)
treee29eddc646811bd754842288678dd2013f51bb44 /docs
parent9608678704a5f89b4c946eea93e90a0f6eb8e3ef (diff)
Fixed #35529 -- Added support for positional arguments in querystring template tag.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/templates/builtins.txt39
-rw-r--r--docs/releases/6.0.txt4
2 files changed, 35 insertions, 8 deletions
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 849faaa46f..f3d967b153 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -964,8 +964,14 @@ output (as a string) inside a variable. This is useful if you want to use
Outputs a URL-encoded formatted query string based on the provided parameters.
-This tag requires a :class:`~django.http.QueryDict` instance, which defaults to
-:attr:`request.GET <django.http.HttpRequest.GET>` if none is provided.
+This tag accepts positional arguments, which must be mappings (such as
+:class:`~django.http.QueryDict` or :class:`dict`). If no positional arguments
+are provided, :attr:`request.GET <django.http.HttpRequest.GET>` is used as the
+default to construct the query string.
+
+Positional arguments are processed sequentially, while keyword arguments are
+treated as key-value pairs, applied last. Later arguments take precedence over
+earlier ones, ensuring the most recent pairs are reflected in the final result.
The result always includes a leading ``"?"`` since this tag is mainly used for
links, and an empty result could prevent the page from reloading as expected.
@@ -1033,16 +1039,33 @@ Handling lists
If ``my_list`` is ``["red", "blue"]``, the output will be
``?color=red&color=blue``, preserving the list structure in the query string.
-Custom QueryDict
-~~~~~~~~~~~~~~~~
+Customizing the base QueryDict
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can pass custom ``QueryDict`` or ``dict`` instances as positional arguments
+to replace ``request.GET``. When multiple arguments are provided, key-value
+pairs from later arguments take precedence over earlier ones.
+
+For example, if ``my_query_dict`` is ``<QueryDict: {'color': ['blue'], 'size':
+['S']}>`` and ``my_dict`` is ``{'color': 'orange', 'fabric': 'silk', 'type':
+'dress'}``, this outputs ``?color=orange&size=S&fabric=silk``.
+
+.. code-block:: html+django
+
+ {% querystring my_query_dict my_dict size="S" type=None %}
+
+If all keys are removed by setting them to ``None``, this outputs ``?``:
.. code-block:: html+django
- {% querystring my_query_dict %}
+ {% querystring my_query_dict my_dict color=None size=None fabric=None type=None %}
+
+Similarly, if all positional arguments are empty and keyword arguments do not
+contribute any new params, the output will also be ``?``.
+
+.. versionchanged:: 6.0
-You can provide a custom ``QueryDict`` to be used instead of ``request.GET``.
-So if ``my_query_dict`` is ``<QueryDict: {'color': ['blue']}>``, this outputs
-``?color=blue``. If ``my_query_dict`` is empty, the output will be ``?``.
+ Support for multiple positional mapping arguments was added.
Dynamic usage
~~~~~~~~~~~~~
diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt
index cd72185354..499163788f 100644
--- a/docs/releases/6.0.txt
+++ b/docs/releases/6.0.txt
@@ -236,6 +236,10 @@ Templates
* The :ttag:`querystring` template tag now consistently prefixes the returned
query string with a ``?``, ensuring reliable link generation behavior.
+* The :ttag:`querystring` template tag now accepts multiple positional
+ arguments, which must be mappings, such as :class:`~django.http.QueryDict`
+ or :class:`dict`.
+
Tests
~~~~~