Class Based Views Part 3: DetailView and template_name Shortcut

The DetailView is an important class based view since it allows us to show off details of our data instead of just bits here and there. It is also very simple to use and will save you time. In this video you are also going to see a nice little shortcut with your templates to save you from writing a couple of extra lines.
todo/urls.py
from django.views.generic import TemplateView, ListView, DetailView

url(r'^(?P<pk>\d+)-(?P<slug>[-\w]+)/$', DetailView.as_view(
    context_object_name="task",
    model=Task,
    ), name="task"),

url(r'^$', ListView.as_view(
    model = Task,
    paginate_by = '5',
    queryset = Task.objects.all(),
    context_object_name = "tasks",)),
comments powered by Disqus