【发布时间】:2023-03-12 20:07:01
【问题描述】:
现在我正在学习 django 并浏览文档。当我尝试使用通用视图时,它给了我一个例外:
File "/home/jeffr/Рабочий стол/codetry/mysite1/polls/views.py", line 8
def IndexView(generic.ListView):
^
SyntaxError: invalid syntax
这是我的意见.py:
from django.views import generic
from .models import Choice, Question
def IndexView(generic.ListView):
template_name = 'polls/index.html'
contest_object_name = 'latest_question_list'
get_queryset(self):
"""Return the last five published questions"""
return Question.objects.order_by('-pub_date')[:5]
def DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'
完整的回溯粘贴可以在这里找到:http://dpaste.com/3QMN3A0
任何帮助将不胜感激,谢谢
【问题讨论】:
-
你定义了一个*函数,你应该使用
class IndexView(...)而不是def IndexView。