python - 人性化 django-tables2 输出?

标签 python django django-tables2

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

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/

相关文章:

Django:如何更改 django-tables2 中的列宽

python - 使用 Django Tables2 为对话框添加单击事件

python - wxPython wx.lib.plot.PlotCanvas 错误

python - 如何使用 to_dict() 创建一个键、值对均为整数的字典?

mysql - Django、nginx 和 uWSGI 缓存结果直到 uWSGI/MySQL 重启

python - django模板生成的html代码

html - django-tables2 每行添加按钮

javascript - 在 Google App Engine 中使用 JavaScript 将可下载文件添加到另一个页面

python - 有向线段之间的符号角

python - Django 中的复杂聚合