Answer the question
In order to leave comments, you need to log in
How to generate a dynamic query string in a template in django?
There is some page with a list of articles based on ListView
I added some hyperlink blocks to sort and display articles for example:
Block 1
Detailed|Shortly
Block 2
Per day|Per week|Per month
Block 3 (number of articles per page)
10|20|50
I pass the output parameters in the query string:
article/?sort=table&pag=10&date=week
I tried to do it through
@register.simple_tag
def dinamic(value, str_filtre, str_value):
<a href="{% url 'article:list' %}{% dinamic request.get_full_path "sort" "list" %}">полно</a>|
article/?sort=table&pag=15&date=week&date=month
Answer the question
In order to leave comments, you need to log in
Hmm in dinamic-e will not be replaced? Use https://docs.python.org/3/library/urllib.parse.htm...
You can generate urls for the current page like this.
@register.simple_tag(takes_context=True)
def dinamic(context, **kwargs):
request = context['request']
qparams = request.GET.dict()
qparams.update(**kwargs)
return '{}?{}'.format(request.path_info,
urlencode(qparams))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question