python - Django 模板中的 "TemplateSyntaxError Invalid block tag: ' trans '"错误

标签 python django django-templates translation templatetags

运行 runserver 命令后,出现以下错误:

TemplateSyntaxError at /questions/ Invalid block tag: 'trans'

有人知道这是什么原因吗?

这是我的模板语法:

{% 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 -->

最佳答案

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

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

您可以使用{% trans“问题”。 %}

如果您要使用 block ,它们需要采用以下格式:

{% blocktrans %}{{ value2translate }}{% endblocktrans %}

更多信息here .

关于python - Django 模板中的 "TemplateSyntaxError Invalid block tag: ' trans '"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24451478/

相关文章:

python - 如何实时更新 django 模板?

python - 呈现 : 'int' object is not iterable in django template 时捕获类型错误

python - pip 在哪里安装它的模块?如果使用 virtualenv 怎么办?设置 mod_wsgi 时也出现错误

python pip 指定一个库目录和一个包含目录

python - 用于从 REST API 读取数据的 Apache Beam Pipeline 在本地运行,但不在 Dataflow 上运行

python - 实现自定义哈希方法

python - 为什么south要用迁移文件呢?

javascript - Django 管理员预填充字段不是错误 "d.Keyup is not a function"

python - django 和 mod_wsgi 的配置问题

javascript - 向下滚动时自动加载内容