December 2016
Beginner to intermediate
694 pages
14h 2m
English
The list/detail generic views handle the common case of displaying a list of items at one view and individual detail views of those items at another.
django.views.generic.list.ListView
Use this view to display a page representing a list of objects.
Example views.py:
from django.views.generic.list import ListView
from django.utils import timezone
from articles.models import Article
class ArticleListView(ListView):
model = Article
def get_context_data(self, **kwargs):
context = super(ArticleListView, self).get_context_data(**kwargs)
context['now'] = timezone.now()
return context
Example myapp/urls.py:
from django.conf.urls import url from article.views import ArticleListView urlpatterns = [ url(r'^$', ArticleListView.as_view(), ...
Read now
Unlock full access