问题
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