2

当存在基于函数的通用视图时,我曾经这样做过

 (r'^foo/$', direct_to_template, {'template': 'foo_index.html'}),

在基于类的视图中这个等价物是什么,所以我不需要在我的views.py

4

1 回答 1

5

That would be the TemplateView, and you use it like:

from django.conf.urls import patterns, url
from django.views.generic.base import TemplateView

urlpatterns = patterns('',
    url(r'^foo/$', TemplateView.as_view(template_name='foo_index.html')),
)
于 2013-02-25T03:18:34.097 回答