Python Django错误中关于页面的顶层

Python Django错误中关于页面的顶层,python,django,django-views,django-class-based-views,Python,Django,Django Views,Django Class Based Views,我想在我的Django网站上有一个顶级的关于页面(例如:http://127.0.0.1:8000/about)指向民意测验应用程序中基于类的关于视图或顶级关于页面,但我得到: TypeError at /about/ __init__() takes 1 positional argument but 2 were given MySite/MySite/url.py: from django.conf.urls import include, url from django.contrib

我想在我的Django网站
上有一个顶级的关于页面(例如:http://127.0.0.1:8000/about)
指向民意测验应用程序中基于类的关于视图或顶级关于页面,但我得到:

TypeError at /about/
__init__() takes 1 positional argument but 2 were given
MySite/MySite/url.py:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    # Examples:
    url(r'^$', 'myPollSite.views.index', name='myPollSite_home'),
    url(r'^about/$', 'myPollSite.views.AboutView', name='myPollSite_about'),
    url(r'^polls/', include('polls.urls', namespace = "polls")),
    url(r'^admin/', include(admin.site.urls)),

]
MySite/MySite/views.py:

from django.shortcuts import render
from django.http import HttpResponse
from django.views import generic

class AboutView(generic.TemplateView):
    template_name = "polls/about.html"


def index(request):
    return HttpResponse("Hello, world. You're at myPollSite index.")
MySite/polls/template/polls/about.html:

<h1>About Page</h1>
<h2>Implemented with TemplateView</h2>
<p>
    No Model Data can be retrieved with Template View
</p>
关于页面
使用TemplateView实现

无法使用模板视图检索任何模型数据

按照中的建议,使用
As_view()配置基于类的视图。
调用:

url(r'^about/$', AboutView.as_view(), name='myPollSite_about'),
其中应导入
AboutView

from myPollSite.views import AboutView

你的url应该是这样的:myPollSite.views.AboutView.as_view()AboutView.as_view()有效,但是为什么当我使用myPollSite.views.AboutView.as_view()时,我得到了一个名称错误:“myPollSite”没有定义?@jerryh91我想你应该刚刚导入
myPollSite
。应该是我提供的选项。