首页 > 解决方案 > 为什么较低的内置过滤器在 Django 模板 2.2 中不起作用?

问题描述

使用Django v2.2模板的内置过滤器。

我的模板如下所示:

    {% load i18n %}{% blocktrans with site_name=current_site.organization.name site_domain=current_site.name %}Hello from {{ site_name }}!

    You're receiving this e-mail because your email is subscribed to receiving notification when a Quotation is Pending PO Release.

    {{ quote_type }}
    {{ quote_type|lower }}

     - Quotation: {{ display_quotation_number }}
     - PO Date: {{ po_date_display }} (New)

    {% endblocktrans %}

    {% blocktrans with site_name=current_site.organization.name site_domain=current_site.name %}Thank you for using {{ site_name }}!
    {{ site_domain }}{% endblocktrans %}

我可以肯定地说,这{{ quote_type }}肯定会打印出一些东西。{{ quote_type|lower }}什么都不打印。

我做错了什么?

我确定过滤器是内置的;见https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#lower

更新

这是我目前的工作,它有效

    extra_context = self.lower_quote_type(extra_context)
    quotation.email_people(
        recipient_list=recipient_list,
        extra_context=extra_context,
    )

def lower_quote_type(self, extra_context):
        # @makeAnIssue temp workard for #1334 but try to permanently fix it elegantly
        if "quote_type" in extra_context:
            extra_context["quote_type"] = extra_context["quote_type"].lower()
        return extra_context

然后这个工作

    {% load i18n %}{% blocktrans with site_name=current_site.organization.name site_domain=current_site.name %}Hello from {{ site_name }}!

    You're receiving this e-mail because your email is subscribed to receiving notification when a Quotation is Pending PO Release.

    {{ quote_type }} # this correctly shows up as lower case


     - Quotation: {{ display_quotation_number }}
     - PO Date: {{ po_date_display }} (New)

    {% endblocktrans %}

    {% blocktrans with site_name=current_site.organization.name site_domain=current_site.name %}Thank you for using {{ site_name }}!
    {{ site_domain }}{% endblocktrans %}

标签: djangodjango-templates

解决方案


推荐阅读