Is there a way to assign multiple variables in a with statement in a django template. I would like to assign several variables in a statement with after returning multiple values from templatetag
My use case:
{% with a,b,c=object|get_abc %} {{a}} {{b}} {{c}} {% endwith %}
I do not think this is possible without a custom templatetag.
However, if your method always returns the same length, you can make it more compact, like this:
{% with a=var.0 b=var.1 c=var.2 %} ... {% endwith %}
I'm not sure if this is allowed, however several assignments are allowed from docs .
3 1 , tuple, .
tuple
{% with var=object|get_abc %} {{ var.0 }} {{ var.1 }} {{ var.2 }} {% endwith %}
Django, , , docs:
Django - Python, HTML. : ,
, Python , , :
{# assuming get_abc returns a dict #} {% with var=object|get_abc %} {{ var.key_a }} {{ var.key_b }} {{ var.key_c }} {% endwith %}
Source: https://habr.com/ru/post/1676947/More articles:Transaction MSDTC advances towards query distribution performed outside the scope of the transaction - c #GraphQL API Testing - node.jsCan you declare multiple variables in a django template? - pythonGetting local file in iOS using native - iosДобавление индекса li в алфавит - htmlThe difference between the takeWhile () and filter () methods in Kotlin - collectionsSVG с xlink: href не работает в Edge - htmlCannot install package packages in python 3.6 due to ssl error - pythonCreate a data frame from a dict where the values are variable-length lists - pythonAccessViolationException occurred in AForge.Video.FFMPEG.dll - .netAll Articles