如何才能渲染这个Django模板?

时间:2016-06-28 18:15:27

标签: python django django-templates pinax

Why is Django blocktrans working one place and not another?中,我问了一个类似的问题,并在“使用i18n”响应解决了相关行为后接受了答案。在这里,我在Pinax 0.9a1的模板中得到一个TemplateSyntaxError,用于查看给定用户的关注者:

{% extends "microblogging/base.html" %}

{% load i18n %}
{% load avatar_tags %}
{% load account_tags %}

{% user_display other_user as other_user_display %}

{% block head_title %}{% blocktrans %}Followers of {{ other_user_display }}{% endblocktrans %}{% endblock %}

错误是:

TemplateSyntaxError at /tweets/followers/ABC/
Caught KeyError while rendering: u'other_user_display'

如果我正确读取模板,模板中倒数第二个(非空白)行定义other_user_displayuser_display()中定义了lib/python2.7/site-packages/pinax/apps/account/utils.py

要使user_display other_user / other_user_display可用,还需要做些什么?

1 个答案:

答案 0 :(得分:1)

在blocktrans标记内定义{{ other_user_display }}变量。 来自https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#blocktrans-template-tag

的第二个例子