check variable type inside Jinja2 in Flask -


the template file created contains this:

{% if type({'a':1,'b':2}) dict %}     print "oh yes!!" {% else %}     print "oh no!!!" {% endif %} 

then jinja2 responds saying:

templateassertionerror: no test named 'dict' 

i new jinja2 , flask

you looking mapping test:

{% if {'a': 1, 'b': 2} mapping %}     "oh yes!" {% else %}     "oh no!" {% endif %} 

jinja not python though, don't have access builtins (type , print not exist, example, unless add them the context. in flask, context_processor decorator).

you don't need print @ all. default output (unless in child template extends parent, in case can interesting things null master fallback because blocks names available in master template output).


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -