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

iro*_*ame 13 sitemap django

我按照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
Run Code Online (Sandbox Code Playgroud)

Mez*_*Mez 43

这是因为它没有找到默认模板.

确保'django.template.loaders.app_directories.load_template_source'在您的TEMPLATE_LOADERS设置中,并确保它在您的设置'django.contrib.sitemaps'INSTALLED_APPS.

  • 啊!因为我为dev/production设置了settings.py/local_settings.py,我忘了把它添加到local_settings.py (2认同)

Ada*_*nce 6

不推荐使用,最新的是:'django.template.loaders.app_directories.Loader',


小智 5

您可以尝试django.contrib.sitesINSTALLED_APPS.

只需添加django.contrib.sitemaps.