如何将if语句放入jinja2的宏中?

  • 本文关键字:jinja2 if 语句 flask jinja2
  • 更新时间 :
  • 英文 :


我有以下宏,如果可能的话,我想在其中放入if语句。

{% macro input(name, plc, required=true, type='text', class='validate') -%}
<input name="{{ name }}" placeholder="{{ plc }}" type="{{ type }}" class="{{ class }}" value="{{ session.get(name) }}" { % if required %} required {% endif %}>
{%- endmacro %}
因此,它抛出以下错误:
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endmacro'. The innermost block that needs to be closed is 'macro'.

我猜是打错了,{ % if required %}多了一个白色字符,应该是{% if required %}

最新更新