Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将标记包含在带有include标记的_Python_Django - Fatal编程技术网

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 %}