文档:https://docs.djangoproject.com/en/1.11/topics/class-based-views/

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic

from .models import Choice, Question


class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """ 返回最近时间的五个问题 """
        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'


def vote(request, question_id):

相关文章:

  • 2021-09-08
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-10-15
  • 2021-10-07
  • 2021-09-29
  • 2021-11-30
猜你喜欢
  • 2021-10-07
  • 2021-11-24
  • 2022-01-10
  • 2021-08-31
  • 2022-12-23
  • 2021-05-28
  • 2021-08-12
相关资源
相似解决方案