如何獲取傳遞給Jinja2模板的所有參數列表?如何獲取Jinja2模板中的參數列表
如果我有一個非常通用的模板,我想列出傳遞(用於調試的原因)的所有參數是有辦法做到這一點?
喜歡的東西:
mytemplate.html
{% for argument in LIST_OF_ARGUMENT %}
{{ argument }}<br>
{% endfor %}
所以在視圖/foobar
如果我把這樣的模板:
return render_template('mytemplate.html', form=myform, foo='bar')
我得到
the_content_of_form <br>
bar <br>
而如果我所說的模板是這樣的:
return render_template('mytemplate.html', lorem=ipsum, fooooo='barrrrr')
我得到
the_content_of_lorem <br>
barrrrr <br>
是的...我應該閱讀文檔。感謝您爲對話做出貢獻。 –
@ZeroPiraeus這種解決方案似乎並不情況下工作,我傳遞給模板的對象與__call __()方法:我會繼續調查(讀取codegeek鏈接的文檔) –