Eu gostaria de ter uma página de nível superior no meu site do Django (eg: http://127.0.0.1:8000/about)
Isso é apontado para a classe com base em visão no aplicativo de enquetes ou um nível superior sobre a página, no entanto eu estou ficando:
TypeError at /about/
__init__() takes 1 positional argument but 2 were given
MySite / Mysite / urls.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>
Respostas:
1 para resposta № 1Como sugerido no documentação, configure sua visão baseada em classe com um as_view()
ligar:
url(r"^about/$", AboutView.as_view(), name="myPollSite_about"),
Onde AboutView
deve ser importado:
from myPollSite.views import AboutView