核心:obj.get_字段名_display
1、定义module 数据结构:
class msg(models.Model): choice = ( (1, '技术部'), (2, '行政'), (3, '人事'), (4, "财务"), ) group = models.IntegerField(choices=choice)
2、views 视图:
def test(request): info = models.msg.objects.all() return render(request,"ceshi.html",{"info":info})
3、在前端显示:
<div> {% for i in info %} <p><span>{{ i.get_group_display }}</span></p> {% endfor %} </div>