【问题标题】:Jinja2 Templates create extra space on empty tags [duplicate]Jinja2模板在空标签上创建额外空间[重复]
【发布时间】:2016-08-18 05:51:13
【问题描述】:
{% block flashes %}
    <section class='flashes'>
        {% with messages = get_flashed_messages() %}
            {% if messages %}
                <ul>
                    {% for message in messages %}
                        <li>{{ message }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
        {% endwith %}
    </section>
{% endblock %}

每当部分标签为空时,我都会在我的 HTML 源视图甚至 chrome 开发工具中看到类似的内容

开发工具


查看源代码


如果我删除缩进和额外的空格,维护会很困难,有什么解决办法吗?谢谢

【问题讨论】:

    标签: python flask whitespace jinja2 removing-whitespace


    【解决方案1】:

    看看whitespace control

    您应该使用{%--%} 而不是{%%}

    【讨论】:

    • 谢谢你的意思是什么?块, if, for , endif ... ?
    • @CameronA 是的。如果你想去掉所有空行
    • 谢谢他的工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    相关资源
    最近更新 更多