我正在试验 Django,并弄清楚如何设置urls.py以及 URL 是如何工作的。我已经在项目的根目录中配置了urls.py,以指向我的博客和管理员。但是现在我想在我的家中添加一个页面,所以在localhost:8000
.
因此,我在项目根目录的urls.py中添加了以下代码:
from django.views.generic.simple import direct_to_template
urlpatterns = patterns('',
(r"^$", direct_to_template, {"template": "base.html"}),
)
问题是它在blog/templates/...中搜索模板, 而不是在我的根目录中搜索模板文件夹。其中包含base.html。
完整的 urls.py:
from django.conf.urls import patterns, include, url
from django.views.generic.simple import direct_to_template
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r"^$", direct_to_template, {"template": "base.html"}),
url(r'^blog/', include('hellodjango.blog.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^tinymce/', include('tinymce.urls')),
)
我忽略了什么吗?