0

我正在尝试查询所有餐厅并将它们显示给我的模型中的用户,但我无法获取模板来显示模型中的项目

{% block content %}
<h1>Featured Restraunts</h1>
<ul>

{% for restaurant in restaurants %}
    <li><h2>{{ restaurants.name }}</h2></li>
{% endfor %}
</ul>

{% endblock %}

this is what i get
Featured Restaurants



and this is my views.py
def view_restaurants(request):
    restaurants = Restaurant.objects.all()
    return render(request,'menu/restaurants.html',{"restaurants":"restaurants",},context_instance=RequestContext(request))    

是拼写错误吗,我只想查看餐厅列表。

如果我在限制浏览器显示后删除 .name

餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅餐厅

即使只有 2 个条目

4

2 回答 2

1

您需要删除变量周围的引号restaurants(也不需要逗号) -

return render(request,'menu/restaurants.html', {"restaurants": restaurants})

也不render需要您设置context_instance.

于 2013-03-09T20:38:20.307 回答
1
{"restaurants":"restaurants",} 

似乎是你的问题

于 2013-03-09T20:39:34.587 回答