首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django TemplateSyntaxError无效块标记:'trans‘

django TemplateSyntaxError无效块标记:'trans‘
EN

Stack Overflow用户
提问于 2014-06-27 12:07:51
回答 4查看 33.7K关注 0票数 17

运行runserver命令后,将得到以下错误:

TemplateSyntaxError at /质询/无效块标记:“trans”

有人知道原因是什么吗?

这是我的模板语法:

代码语言:javascript
复制
     {% extends "two_column_body.html" %}
{# 
    this template is split into several
    blocks that are included here
    the blocks are within directory templates/main_page
    relative to the skin directory

    there is no html markup in this file
#}
<!-- questions.html -->
{% block forejs %}
    {% include "main_page/custom_head_javascript.html" %}
{% endblock %}
{% block title %}{% spaceless %}{% trans %}Questions{% endtrans %}{% endspaceless %}{% endblock %}
{% block content %}
    {% include "main_page/tab_bar.html" %}
    {% include "main_page/headline.html" %}
    {# ==== BEGIN: main_page/content.html === #}
    <div id="question-list">
        {% include "main_page/questions_loop.html" %}
    </div>
    {# ==== END: main_page/content.html === #}
    {% include "main_page/paginator.html" %}
{% endblock %}
{% block sidebar %}
    {% include "main_page/sidebar.html" %}
{% endblock %}
{% block endjs %}
    <script type="text/javascript">
        {# cant cache this #}
        askbot['settings']['showSortByRelevance'] = {{ show_sort_by_relevance|as_js_bool }};
        askbot['messages']['questionSingular'] = '{{ settings.WORDS_QUESTION_SINGULAR|escapejs }}';
        askbot['messages']['answerSingular'] = '{{ settings.WORDS_ANSWER_SINGULAR|escapejs }}';
        askbot['messages']['acceptOwnAnswer'] = '{{ settings.WORDS_ACCEPT_OR_UNACCEPT_OWN_ANSWER|escapejs }}';
        askbot['messages']['followQuestions'] = '{{ settings.WORDS_FOLLOW_QUESTIONS|escapejs }}';
    </script>
    {% include "main_page/javascript.html" %}
    {% include "main_page/custom_javascript.html" %}
{% endblock %}
<!-- end questions.html -->
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-06-27 12:15:04

{% trans %}Questions{% endtrans %}不是正确的格式。

{% load i18n %}应该位于模板的顶部,或者使用翻译的任何扩展模板。

您可以使用{% trans "Questions." %}

如果要使用块,则必须采用以下格式:

代码语言:javascript
复制
{% blocktrans %}{{ value2translate }}{% endblocktrans %}

更多信息,这里

票数 40
EN

Stack Overflow用户

发布于 2014-06-27 12:18:25

也许您应该使用{% blocktrans %}Questions{% endblocktrans %},而忘记将{% load i18n %}放在模板的顶部。

票数 5
EN

Stack Overflow用户

发布于 2017-06-23 16:02:31

这是因为您没有在此模板i18n中加载{% load i18n %},所以必须在每个模板中添加此内容。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24451478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档