python - How to define nested variables in flask jinjia2
迷茫
迷茫 2017-06-22 11:51:50
0
1
1273

In jinjia, as shown below, I defined a variable number

{% set number = unit %}

file_dict is a dict type variable. I want to reference the key in file_dict so as to find the value in file_dict where the key is {{number}}

{{file_dict{{number}}}}

It seems that it is illegal to define it like the above, and it cannot be passed.
In addition, macro definition cannot be used either.

{% macro get_value(number) %}
             {{ pdf_dict{{number}}}}
{% endmacro %}

Is there any way to define nested variables

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
扔个三星炸死你

I solved it myself. I was reminded that jinjia2 variables have __getitem__ syntax. Just call get directly instead of accessing the attribute. Because after that, instead of calling the variable, I called the string. Wrapping it directly with double brackets would not work. Grammarly

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template