Python 在Django中显示表项列表

Python 在Django中显示表项列表,python,django,django-templates,django-views,Python,Django,Django Templates,Django Views,我有一个数据库表,允许您输入特定人员的详细信息。然后如何列出该表的所有条目以显示添加到数据库中的所有人员 url.py url(r'^accounts/loggedin/locations/all/$', 'assessments.views.locations'), url(r'^accounts/loggedin/locations/get/(?P<location_id>\d+)$', 'assessments.views.location'), url(r'^accoun

我有一个数据库表,允许您输入特定人员的详细信息。然后如何列出该表的所有条目以显示添加到数据库中的所有人员

url.py

url(r'^accounts/loggedin/locations/all/$', 'assessments.views.locations'),
url(r'^accounts/loggedin/locations/get/(?P<location_id>\d+)$',   'assessments.views.location'),
url(r'^accounts/loggedin/locations/create/$', 'assessments.views.create'),
view.py

def people(request):
    return render_to_response('dashboard/people.html', {'people': People.objects.all})
people.html

<body>
    <h1>People</h1>
    {% for p in people %}
    <h1><a href="/people/get/{{ people.id }}/">{{ people.first_name }}</a></h1>
    {% endfor %}
    </body>
</html>
两个问题:

您应该调用all以获得结果,注意:

在模板中,您应该使用{p.first_name}而不是{{people.first_name}},因为您迭代的是people变量,基本上是一个对象列表


您现在的输出是什么?看起来您应该在for中使用{{p.first_name}}。这样,如果您的数据是正确的,它将迭代所有人,并为每个人打印一个正确的姓名。问题是什么?我已经尝试了建议的内容,但在屏幕上没有得到任何输出。它是正义的银行
<body>
    <h1>People</h1>
    {% for p in people %}
    <h1><a href="/people/get/{{ people.id }}/">{{ people.first_name }}</a></h1>
    {% endfor %}
    </body>
</html>
People.objects.all()