我在models.py中有模型:
class Category(models.Model):
name = models.CharField('Nazwa Kategorii', max_length=100)
slug = models.SlugField('Odnośnik', unique=True, max_length=100)
icon = models.ImageField('Ikonka Kategorii', upload_to='icons',
blank=True)
class Meta:
verbose_name = "Kategoria"
verbose_name_plural = "Kategorie"
def __unicode__(self):
return self.name
我想查看所有类别的列表:views.py
class CategoryList(generic.ListView):
model = models.Category
context_object_name = 'category_list'
category_list = CategoryList.as_view()
在 base.html 我有:
{% for entry in category_list %}
<li><a href="#">{{ entry.name }} </a></li>
{% endfor %}
但它不会返回任何类别。我想念什么?我想添加带有类别列表的基本模板菜单..