include模板标记中的Django变量替换

include模板标记中的Django变量替换,django,django-templates,variable-substitution,Django,Django Templates,Variable Substitution,我有一个国际化的Django 1.3站点,希望做到这一点: {% include "snippets/button.html" with button_text=_("Logout {{ user.username }} now") %} 而snippets/button.html如下所示: <button type="{{ button_type|default:_('submit') %}" class="all_my special classes" {% if but

我有一个国际化的Django 1.3站点,希望做到这一点:

{% include "snippets/button.html" with button_text=_("Logout {{ user.username }} now") %}
snippets/button.html
如下所示:

<button
  type="{{ button_type|default:_('submit') %}"
  class="all_my special classes"
  {% if button_title %} title="{{ button_title }}"{% endif %}>
  <span class=ui-button-text>{{ button_text|default:_("Submit") }}</span>
</button>

但这是不可接受的,因为要转换的字符串需要包括变量替换发生的位置。我见过,但这不包括这种用法。

类似的内容可能会让您继续:

{% blocktrans with value|filter as myvar %}
  This will have {{ myvar }} inside.
{% endblocktrans %}
从这里


它应该与include一起工作,但我还没有测试。

我认为在这种情况下,最好的办法是将已经翻译的字符串添加到上下文中

在您的
视图.py
中:

...
'button_text': _("Logout {} now").format(user.username),
...
然后在模板中:

{% include "snippets/button.html" with button_text=button_text %}
{% include "snippets/button.html" with button_text=button_text %}