【问题标题】:How can I get this Django template to render?如何让这个 Django 模板渲染?
【发布时间】:2016-10-31 05:02:51
【问题描述】:

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 可用?

【问题讨论】:

    标签: python django django-templates pinax


    【解决方案1】:

    在 blocktrans 标记中定义您的 {{ other_user_display }} 变量。 第二个例子来自https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#blocktrans-template-tag

    【讨论】:

      猜你喜欢
      • 2020-10-21
      • 2017-10-13
      • 2022-07-22
      • 2018-05-20
      • 2018-11-05
      • 2021-11-25
      • 1970-01-01
      • 2013-06-16
      • 2013-10-10
      相关资源
      最近更新 更多