Django: Using template.render() and l10n



我有一段代码,用于发送带有附加CSV文件的电子邮件。CSV包含定价信息。我所在的国家使用逗号作为小数分隔符,因此我希望在CSV数据中转换价格。然而,这并没有像预期的那样工作。

代码使用了一个模板,该模板也在应用程序的另一部分中用于生成这些csv。在本例中,转换按预期工作。

My l10n &I18n配置如下:

LANGUAGE_CODE = 'nl-NL'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True
USE_L10N = True
USE_TZ = True
负责手动解析模板的代码:
template = get_template("template_file.html")
context = Context({'object_list': get_object_list()}, use_l10n=True)
csv = template.render(context)

模板的一部分:

Aantal;Eenheid;Product;Omschrijving;Inkoopprijs Euro
{%  for product in object_list %}"{{ product.amount_sum }}";"{{ product.unit_of_measurement }}";"{{ product.name }}";"{{ product.description }}";"{{ product.base_price }}"
{% endfor %} 

(base_priceDecimalField)

您应该在这里使用RequestContext:

context = RequestContext(request, {'object_list': get_object_list()}, use_l10n=True)

最新更新