Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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 Django模板:使用变量转换包含_Python_Django_Templates - Fatal编程技术网

Python Django模板:使用变量转换包含

Python Django模板:使用变量转换包含,python,django,templates,Python,Django,Templates,我有一个模板,您可以在其中传递文本变量。我想将此模板包含到另一个模板中,但它的变量是翻译文本。你如何做到这一点 我想要这样的东西: {% include "a_dir/stuff.html" with text={% trans "Load more promotions" %} %} 我很难编写自己的模板标记,该标记将执行ugettext,但在创建.po文件时,文本变量不会自动获取 我不想在视图中做这项工作,因为我们的所有翻译都在模板中进行。您可以将翻译后的字符串放入一个变量中,并使用作为语

我有一个模板,您可以在其中传递文本变量。我想将此模板包含到另一个模板中,但它的变量是翻译文本。你如何做到这一点

我想要这样的东西:

{% include "a_dir/stuff.html" with text={% trans "Load more promotions" %} %}
我很难编写自己的模板标记,该标记将执行
ugettext
,但在创建
.po
文件时,文本变量不会自动获取


我不想在
视图中做这项工作,因为我们的所有翻译都在模板中进行。

您可以将翻译后的字符串放入一个变量中,并使用
作为
语法。例如:

{% trans "Load more promotions" as promotions %}
{% include "a_dir/stuff.html" with text=promotions %}
有关更多详细信息,请参阅