更新时间:2023-02-26 08:49:40
我在django-admin中无法正常工作。由于我不在面向用户的网站上使用admin,因此现在让数字以逗号而不是点的形式设置。
I did NOT get it working properly in the django-admin. Since I do not use the admin for user-facing sites, I'll let the numbers be formatted with commas instead of dots for now.
但是,在其他模板中根据 django文档a>。
However, in other templates I resorted to using a custom template tag, based on the django documentation.
from django import template
from django.utils.encoding import force_text
register = template.Library()
@register.filter
def intdot(val_orig):
"""
Similar to 'django.contrib.humanize.intcomma', but with dots.
"""
val_text = force_text(val_orig)
try:
val_new = int(val_text)
except ValueError:
return ''
val_new = '{:,d}'.format(val_new)
val_new = val_new.replace(',', '.')
return val_new