Py学习  »  Django

[精华] 求助,关于模板中choices的渲染问题

Hiro • 10 年前 • 3948 次点击  

我在models.py中定义了如下choices

class Node(models.Model):
  GroupChildType = (
      ('nochild', '无子节点'),
      ('or', '分类'),
      ('and', '核心'),
  )
  childtype = models.CharField(max_length=20, choices=GroupChildType)

在模板中渲染完成后直接输出了'nochild',并没有输出'无子节点',请问如何才能让模板中显示后面的value值呢?

views.py

def index(request):
    nodes = Node.objects.all()
    return render_to_response('index.html', {'nodes': nodes, 'user': request.user}, context_instance=RequestContext(request))

index.html

<h3 class="panel-title">{{ node.childtype }}</h3>

我希望在模板中输出 无子节点,而不是nochild。大家帮帮忙,谢谢了。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/720
 
3948 次点击  
文章 [ 2 ]  |  最新文章 10 年前