gpt4 book ai didi

python - 人性化 django-tables2 输出?

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:04 26 4
gpt4 key购买 nike

这是我目前正在使用的一个技巧:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com