I am trying to create an index page for my home app using Django. I would like for the urls.py
file to point directly to an index.html
file in my templates folder within the home app. Therefore, I have the following:
我正在尝试使用Django为我的家庭应用程序创建索引页面。我想让urls.py文件直接指向家庭应用程序中我的templates文件夹中的index.html文件。因此,我有以下几点:
urlpatterns = patterns('',url(r'^$',template_name='index.html'),)
This gives me an error when I load the page, however.
但是,当我加载页面时,这会给我一个错误。
url() got an unexpected keyword argument 'template_name'.
All the resources I have looked at have a view instead of directly linking to an html, but I simply want to go to an index page. How can I achieve this? Thank you!
我查看的所有资源都有一个视图,而不是直接链接到一个html,但我只是想去一个索引页面。我怎样才能做到这一点?谢谢!
1 个解决方案
#1
1
As per Django documentation:
根据Django文档:
This would be a proper way of doing it:
这将是一种正确的方法:
from django.conf.urls import patterns
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^about/', TemplateView.as_view(template_name="about.html")),
)
#1
1
As per Django documentation:
根据Django文档:
This would be a proper way of doing it:
这将是一种正确的方法:
from django.conf.urls import patterns
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^about/', TemplateView.as_view(template_name="about.html")),
)