我有一个Django应用,其中有以下代码:
[app] /urls.py
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
...
]
[app] /views.py
from django.http import HttpResponseRedirect
from .models import Chat
from .models import Message
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.views import generic
from django.utils import timezone
from django.contrib.auth.decorators import login_required
@login_required()
class IndexView(generic.ListView):
template_name = "trout_line/index.html"
context_object_name = 'latest_chat_list'
def get_queryset(self):
"""Return the last five published questions."""
return Chat.objects.filter(start_date__lte=timezone.now()).order_by('-start_date')[:5]
和位于[app]/templates/[app]/index.html
的模板。
运行服务器时,我收到以下消息。
... path('', views.IndexView.as_view(), name='index'),
AttributeError: 'function' object has no attribute 'as_view'
我以为我密切关注了本教程,但是显然我遗漏了一些东西。任何帮助将不胜感激。
我正在Ubuntu 16上运行Python 3.6和Django 2.1.2