Class-based generic views (and any class-based views that inherit from the base classes Django provides) can be configured in two ways: subclassing, or passing in arguments directly in the URLconf.
クラスベースの汎用ビューは2つの方法で設定できる.サブクラス化するか、またはURLconfの中で直接引数を渡すか、である.
TemplateViewをサブクラス化する
# some_app/views.py
from django.views.generic import TemplateViewclass AboutView(TemplateView):
template_name = "about.html"
URLconfに新しいビューを追加する
# urls.py
from django.conf.urls.defaults import *
from some_app.views import AboutViewurlpatterns = patterns('',
(r'^about/', AboutView.as_view()),
)
または・・・
from django.conf.urls.defaults import *
from django.views.generic import TemplateViewurlpatterns = patterns('',
(r'^about/', TemplateView.as_view(template_name="about.html")),
)