为“Django”应用创建Sitemap时出现“TemplateDoesNotExist”错误

时间:2009-10-18 22:59:52

标签: django sitemap

我按照django网站上的站点地图激活步骤,但我一直收到'TemplateDoesNotExist'错误。也许我是误会,但不是应该生成页面的genericview吗?

########### url.py #############################3

.........
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
........
........
info_dict = {
'queryset': Bookmark.objects.all(),
'date_field': 'added'
}
sitemaps = {
'bookmarks': GenericSitemap(info_dict, changefreq = 'never', priority=0.6),
}
urlpatterns = patterns('',
.............
url(r'^$', 'microblogging.views.public', name="home"),
(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
.............
)
if settings.SERVE_MEDIA:
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'misc.views.serve')
)



############# error #############################

TemplateDoesNotExist at /sitemap.xml

sitemap.xml

Request Method: GET
Request URL: http://localhost:8000/sitemap.xml
Exception Type: TemplateDoesNotExist
Exception Value:

sitemap.xml

Exception Location: /usr/lib/python2.5/site-packages/django/template/loader.py in find_template_source, line 73
Python Executable: /usr/bin/python2.5
Python Version: 2.5.4

4 个答案:

答案 0 :(得分:42)

这是因为它找不到默认模板。

确保'django.template.loaders.app_directories.load_template_source'设置为TEMPLATE_LOADERS,并确保'django.contrib.sitemaps'中有INSTALLED_APPS

答案 1 :(得分:6)

已弃用,最新版本为:'django.template.loaders.app_directories.Loader',

答案 2 :(得分:1)

您可以尝试从django.contrib.sites中删除INSTALLED_APPS

只需添加django.contrib.sitemaps

答案 3 :(得分:0)

无需再添加 this.http.post('/api/fmng/create', body, { headers: headers }).subscribe(data => { console.log(data); });