繁体   English   中英

人性化django-tables2输出?

[英]Humanizing django-tables2 output?

这是我正在使用的黑客攻击:

class ProductMaxIPPortEldCountMonthlyTable(tables.Table):                      
    ip_count = tables.TemplateColumn('{% load humanize %}{{ record.ip_count|intcomma }} ')

我正在使用django.contrib.humanize 是否有更清洁的方法来实现这种效果?

您可以导入intcomma模板过滤器,并为使用它的列定义自定义呈现方法

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM