在with include标记中包含标记

时间:2013-06-27 16:59:00

标签: python django

如何插入此内容:

<strong>{% trans "Error!" %}</strong> {% trans "blablabla." %}

而不是“xxx”:

{% include "alert.html" with connotation="error" message="xxx" %}

请告知。

1 个答案:

答案 0 :(得分:0)

据我所知,除非您在视图中创建完整的消息并将其作为模板上下文参数传递,否则不能这样做。

我会建议传递一些错误代码,而不是传递完整的消息,并在此基础上显示"alert.html"中的相应消息。

所以你的include语句将改为:

{% include "alert.html" with connotation="error" error_code=err_code %}

并在alert.html内,您可以设置条件以显示相应的消息。

{% if error_code == "404" %}
  <strong>{% trans "Not Found!" %}</strong>
{% endif %}
相关问题