在与包括标签包括标签
问题描述:
我怎样才能插入此:在与包括标签包括标签
<strong>{% trans "Error!" %}</strong> {% trans "blablabla." %}
而是 “XXX” 在这里:
{% include "alert.html" with connotation="error" message="xxx" %}
请指教。
答
据我所知,除非在视图中创建完整的消息并将其作为模板上下文参数传递,否则不能这么做。
而不是传递完整的消息,我会建议通过一些错误代码,并基于那在"alert.html"
显示适当的消息。
所以,你的包含语句将变成这样的事情:
{% include "alert.html" with connotation="error" error_code=err_code %}
和内部alert.html
,你可以把条件显示相应的消息。
{% if error_code == "404" %}
<strong>{% trans "Not Found!" %}</strong>
{% endif %}
你到目前为止做了什么? – zmo
你不能。为了实现它,您可以修改'alert.html'模板以有条件地显示您想要传递的块,例如'{%if message%} .. block goes here .. {%endif%}' – J0HN