django 学习笔记四

通用视图模式

from django.views import generic

class IndexView(generic.ListView):

    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        ''' return the last five pulished quesitons.'''
        return Question.objects.order_by('pub_date')[:5]


class DetailView(generic.DetailView):

    model = Question

    template_name = 'polls/detail.html'


class ResultsView(generic.DetailView):

    model = Question

    template_name = 'polls/results.html'

generic.DetailView 代表

你可能感兴趣的:(django 学习笔记四)