我使用{{ order.total_gross|currencynofmt:order.event.currency }}
显示200.00,使用{{ order.total_gross|currencyfmt:order.event.currency }}
显示$ 200.00
正在发生的变化是format=True
或format=False
。我想知道是否有一种方法可以将其引入一个模板标签,因为它们非常相似。
register = template.Library()
@register.filter
def currencyfmt(amount, currency_iso_code):
return smallest_currency_unit_converter(
amount,
currency_iso_code,
reverse=True,
format=True
)
@register.filter
def currencynofmt(amount, currency_iso_code):
return smallest_currency_unit_converter(
amount,
currency_iso_code,
reverse=True,
format=False
)
答案 0 :(得分:0)
from django import template
register = template.Library()
@register.simple_tag(takes_context=False)
def currencyrepresentation(amount, currency_iso_code, format):
return smallest_currency_unit_converter(
amount,
currency_iso_code,
reverse=True,
format=format
)
并在您的模板中:
{% currencyrepresentation amount currency_iso_code format as currency_formatted %}
{{currency_formatted}}