django-templates - 上下文值/变量未在blocktrans模板标签内呈现

标签 django-templates django-i18n

我有一个上下文处理器,它将对象(即site)添加到模板上下文中,但是该值未在{% blocktrans %}模板标记内呈现。在template标签之外,该值可以正常打印。

<h1>{% trans "About" %} {{ site.domain }}</h1> <!-- works -->

{% blocktrans %}
   {{ site.domain }} <!-- doesn't work -->
{% endblocktrans %}


如何获取对象的属性/变量以在{% blocktrans %}中呈现?

最佳答案

插值变量不能为点分表达式-您需要以下内容:

{% blocktrans with site_domain=site.domain %}{{ site_domain }} is a ...{% endblocktrans %}


也可以看看:


Django documentation: blocktrans template tag
Question: django blocktrans and i18n in templates

关于django-templates - 上下文值/变量未在blocktrans模板标签内呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007373/

相关文章:

python - 使用 BeautifulSoup 写入文件时在 Django 模板中保留空格

django - Django: “load”(在模板文件中)做什么?

django - 如何使用 "include"标签在 Django 中动态包含模板

django - I18n停止工作

Django i18n + 模板包含标签

当时区支持处于事件状态时,Django DateTimeField 收到了一个天真的日期时间

javascript - Django makemessages javascript(xgettext)

python - 无法解析余数 : '!=None' from '!=None' | Django Admin

python - Django session 翻译设置对所有语言都是粘性的,除了中文?

python - django 模板 - 如何动态访问变量?