Jinja2 inline comments

后端 未结 3 1547
天命终不由人
天命终不由人 2020-12-24 10:42

How can I put comments inside Jinja2 argument list declaration ?

Everything I have tried gives an error: jinja2.exceptions.TemplateSyntaxError: unexpected ch

相关标签:
3条回答
  • 2020-12-24 10:55

    Now Jinja2 has a comment statement:

    {% comment %}
    
        <html code/>
        {% some other statements %}
        {{ some.values }}
    
    {% endcomment %}
    
    0 讨论(0)
  • 2020-12-24 11:00

    Jinja2 has no support for comments within a {{ ... }} statement. You can only use comments outside of such statements, and then only with {# .. #} or ## comment.

    • {# .. #} is only meant for disabling part of a template or adding comments outside of other Jinja2 syntax. You can't nest these.
    • # statement is the equivalent of {% statement %}, if line statements are enabled and so configured.
    • ## comment only works if line statements are enabled, at which point it regarded as a comment.

    Generally, outside of Jinja statements, use comments in the target language instead; e.g. <!-- comment --> when generating XML, etc.

    0 讨论(0)
  • 2020-12-24 11:09

    I was trying to add comments to Martijn Pieters.

    {% .. %} = {# .. #}

    {{ .. }} = {# .. #} (same as above)

    0 讨论(0)
提交回复
热议问题