# In views
def zbsservice(request):
#返回一个列表
v1 = models.Business.objects.all()
# .value返回一个字典
v2 = models.Business.objects.all().values("id","caption","code")
# .values_list 返回一个元组
v3 = models.Business.objects.all().values_list('id','caption')
return render(request,'zbsservice.html',{'v1':v1,'v2':v2,'v3':v3})
# In html
ServiceName:(列表)
{% for item in v1 %}
{ { item.id }}- { { item.caption }}- { { item.code }}{% endfor %}
ServiceName:(字典)
{% for item in v2 %}
{ { item.id }}- { { item.caption }}- { { item.code }}{% endfor %}
ServiceName:(元组)
{% for item in v3 %}
{ { item.0 }}- { { item.1 }}{% endfor %}
Django - 获取表单数据的三种方式<