如何在不使用视图的情况下指向urls.py中的网页

时间:2015-02-03 18:03:00

标签: python django

我正在尝试使用Django为我的家庭应用程序创建索引页面。我希望urls.py文件直接指向家庭应用程序中我的模板文件夹中的index.html文件。因此,我有以下内容:

urlpatterns = patterns('',url(r'^$',template_name='index.html'),)

但是,当我加载页面时,这会给我一个错误。

url() got an unexpected keyword argument 'template_name'.

我查看过的所有资源都有一个视图,而不是直接链接到html,但我只是想去一个索引页面。我怎样才能做到这一点?谢谢!

1 个答案:

答案 0 :(得分:1)

根据Django documentation

这是一种正确的方法:

from django.conf.urls import patterns
from django.views.generic import TemplateView

urlpatterns = patterns('',
    (r'^about/', TemplateView.as_view(template_name="about.html")),
)
相关问题