mirror of
https://github.com/django/django.git
synced 2025-04-06 22:46:41 +00:00
Improved and reorganized querystring template tag docstring and ref docs.
This commit is contained in:
parent
639eafbd27
commit
b1c1fd33ed
@ -1175,24 +1175,25 @@ def now(parser, token):
|
||||
@register.simple_tag(name="querystring", takes_context=True)
|
||||
def querystring(context, query_dict=None, **kwargs):
|
||||
"""
|
||||
Add, remove, and change parameters of a ``QueryDict`` and return the result
|
||||
as a query string. If the ``query_dict`` argument is not provided, default
|
||||
to ``request.GET``.
|
||||
Build a query string using `query_dict` and `kwargs` arguments.
|
||||
|
||||
This tag constructs a new query string by adding, removing, or modifying
|
||||
parameters, starting from the given `query_dict` (defaulting to
|
||||
`request.GET`). Keyword arguments are processed sequentially, with later
|
||||
arguments taking precedence.
|
||||
|
||||
For example::
|
||||
|
||||
{# Set a parameter on top of `request.GET` #}
|
||||
{% querystring foo=3 %}
|
||||
|
||||
To remove a key::
|
||||
|
||||
{# Remove a key from `request.GET` #}
|
||||
{% querystring foo=None %}
|
||||
|
||||
To use with pagination::
|
||||
|
||||
{# Use with pagination #}
|
||||
{% querystring page=page_obj.next_page_number %}
|
||||
|
||||
A custom ``QueryDict`` can also be used::
|
||||
|
||||
{# Use a custom ``QueryDict`` #}
|
||||
{% querystring my_query_dict foo=3 %}
|
||||
"""
|
||||
if query_dict is None:
|
||||
|
@ -996,17 +996,6 @@ Outputs the current query string verbatim. So if the query string is
|
||||
Outputs the current query string with the addition of the ``size`` parameter.
|
||||
Following the previous example, the output would be ``?color=green&size=M``.
|
||||
|
||||
Custom QueryDict
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% querystring my_query_dict %}
|
||||
|
||||
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``.
|
||||
|
||||
Setting items
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
@ -1040,6 +1029,17 @@ 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
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% querystring my_query_dict %}
|
||||
|
||||
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``.
|
||||
|
||||
Dynamic usage
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user