Why is Django blocktrans working one place and not another?

女生的网名这么多〃 提交于 2019-12-13 06:14:16

问题


I have two Django templates (in a Pinax 0.9.x project) with text in a blocktrans block. One is working and the other isn't.

The one that's working looks like:

{% extends "site_base.html" %}

...

{% block body %}

    <h1>ABC</h1>

    <h2><em>DEF</em></h2>

    <p>
        {% blocktrans %}
        GHI
        ...

The one that's not working is getting a debug mode error of:

TemplateSyntaxError at /JKL/
Invalid block tag: 'blocktrans', expected 'endblock' or 'endblock body'

It follows those headings by giving the following source code, with the blocktrans highlighted in red:

{% extends "site_base.html" %}
{% block head_title %}MNO{% endblock %}

{% block body %}
    <p>
        {% blocktrans %}
        PQR
        {% endblocktrans %}
    </p>

Are these two blocks of code isomorphic? If they aren't, what is the difference? What should I be doing to have paragraphs with their content working in blocktrans tags?

Thanks,


回答1:


You have to load the i18n template tags:

<!-- your_template.html -->
{% load i18n %}


来源:https://stackoverflow.com/questions/38082128/why-is-django-blocktrans-working-one-place-and-not-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!