Python 将标记包含在带有include标记的
如何插入以下内容:Python 将标记包含在带有include标记的,python,django,Python,Django,如何插入以下内容: <strong>{% trans "Error!" %}</strong> {% trans "blablabla." %} 请告知。据我所知,除非在视图中创建完整的消息并将其作为模板上下文参数传递,否则无法执行此操作 我建议不要传递完整的消息,而是传递一些错误代码,并在此基础上在“alert.html”中显示相应的消息 因此,您的include语句将更改为以下内容: {% include "alert.html" with connotation=
<strong>{% trans "Error!" %}</strong> {% trans "blablabla." %}
请告知。据我所知,除非在视图中创建完整的消息并将其作为模板上下文参数传递,否则无法执行此操作 我建议不要传递完整的消息,而是传递一些错误代码,并在此基础上在
“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 %}
{%if error\u code==“404”%}
{%trans“未找到!”%}
{%endif%}
到目前为止,您试图做什么?您做不到。为了实现此目的,您可以修改alert.html
模板,以有条件地显示要传递的块,例如{%if message%}..block在这里..{%endif%}
{% if error_code == "404" %}
<strong>{% trans "Not Found!" %}</strong>
{% endif %}