这是我目前正在使用的一个技巧:
class ProductMaxIPPortEldCountMonthlyTable(tables.Table):
ip_count = tables.TemplateColumn('{% load humanize %}{{ record.ip_count|intcomma }} ')
我正在使用 django.contrib.humanize
。有没有更简洁的方法来实现这种效果?
最佳答案
您可以导入 intcomma
模板过滤器,并定义一个 custom render method对于使用它的列。
from django.contrib.humanize.templatetags.humanize import intcomma
class ProductMaxIPPortEldCountMonthlyTable(tables.Table):
ip_count = tables.Column()
def render_ip_count(self, value):
return intcomma(value)
关于python - 人性化 django-tables2 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30375788/