我已经使用官方文档将Django消息添加到了我的应用中。它说要在我的模板中添加以下内容:
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
我不知道百分号是做什么的,它们不是实际的HTML吗?
这是html页面中使用的模板引擎语法,当您使用上下文变量渲染视图html并返回基本的html响应时,django会对其进行编译。
In your case your message will be your context variable and django engine compile it like
:
如果消息不是None,则内部html可见。
Doc。链接:https://docs.djangoproject.com/en/1.7/topics/templates/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句