django自定义模板显示不同状态的颜色
一般这个颜色列表是放在models.py里
charge_type_class_mapping = {
1: "success",
2: "danger",
3: "default",
4: "info",
5: "primary",
}
color.py
from django.template import Library
from web import models
register = Library()
@register.filter()
def type_color(charge_type_num):
return models.TransactionRecord.charge_type_class_mapping[charge_type_num]
本文来自博客园,作者:super_ip,转载请注明原文链接:https://www.cnblogs.com/superip/p/17276011.html