网址.py
from item.models import ItemCategory, Item
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('order.views',
url(r'^$', 'index'),
url(r'category/$', 'category'),
url(r'(?P<cat_id>\d+)/$', 'item'),
)
视图.py
from django.http import HttpResponse
from item.models import ItemCategory, Item
from django.shortcuts import render_to_response, get_object_or_404
def item(request, cat_id):
item_list = get_object_or_404(ItemCategory, pk=cat_id)
return render_to_response('order/item.html', {'item_list':item_list})
项目.html
{% if item_list %}
<h3>{{ item_list.name }}</h3>
<ul>
{% for item in item_list.choice_set.all %}
<li>{{ item.id }} - {{ item.item }}</li>
{% endfor %}
</ul>
{% endif %}
鉴于上述代码,它应该显示:
第一类
- item 1
- item 2
但它只是这样显示:
第一类
它不显示项目
这可能有什么问题?