search

Home  >  Q&A  >  body text

Jinja2 template syntax macro error - Stack Overflow

{% macro msg_error(name) %}
    {% for error in form.{{ name }}.errors %}
      <H5>{{ error }}</H5>
    {% endfor %}
{% endmacro %}

I used macros in the jinja2 template syntax, but an error was reported. The problem is that the name is quoted incorrectly. How should the name be quoted correctly?

phpcn_u1582phpcn_u15822751 days ago944

reply all(1)I'll reply

  • 迷茫

    迷茫2017-06-12 09:27:17

    For example

    @app.route('/error')
    def func_error(func_name):
        return render_template('error.html',name=func_name)
        

    name is the variable name in your template

    reply
    0
  • Cancelreply