I'm trying to build my own Blog app with Django 1.6. I've generated a category list by generic views like this:
urls.py
url(r'^categories/?$', views.ListView.as_view(model=Category), name='categories'),
category_list.html
<h3>Categories</h3>
{% for category in object_list %}
<ul>
<li>{{ category.title }}</li>
</ul>
{% endfor %}
all categories are now listed at /categories
.
My problem is when I add it to base.html
or index.html
file, output changes to article.title
not category.title
How can I add this Category list to other pages such as Index or Article?
Here's my complete views.py file:
views.py
from django.shortcuts import get_object_or_404, render
from django.views.generic import ListView, DetailView
from blog.models import Article, Category
class IndexView(ListView):
template_name = 'blog/index.html'
context_object_name = 'latest_article_list'
def get_queryset(self):
return Article.objects.order_by('-pub_date')[:10]
class ArticleView(DetailView):
model = Article
template_name = 'blog/article.html'