在Django模板中,这两者之间有什么区别呢?
{% blocktrans %}My Text{% endblocktrans %} {% trans 'My Text' %}
解决方法
从
Django Docs
Trans模板标签
The {% trans %} template tag translates either a constant string (enclosed in single or >double quotes) or variable content:
使用Trans标签,您仅限于单个常量字符串或变量.所以你必须使用
{# These Would Work! #} title>{% trans "This is the title." %}</title> <title>{% trans myvar %}</title>
但不能使用
{%trans "This is my title {{ myvar }}" %}
Blocktrans模板标签
Contrarily to the trans tag,the blocktrans tag allows you to mark complex sentences
consisting of literals and variable content for translation by making use of placeholders:
使用Blocktrans,这种代码是可行的:
{% blocktrans with book_t=book|title author_t=author|title %} This is {{ book_t }} by {{ author_t }} {% endblocktrans %}
所以Blocktrans将允许你在你的输出中更复杂一些.
但是从字面上回答你的问题:没有多少.除了演示风格,两者都将作为字符串“我的文本”发送到翻译器