Sitemap Index with Cache gives a NoReverseMatch exception

128 views
Skip to first unread message

Jay Klehr

unread,
Sep 10, 2006, 9:45:12 PM9/10/06
to django...@googlegroups.com
Hello,

Following the djangoproject.com Sitemap example and the documentation on
Sitemaps I'm trying to implement a caching Sitemap Index that will link
out to other Sitemaps for my site (one for each main model basically).
I had the Sitemap Index working with the separate sitemaps just fine
until I decided I wanted to add caching in my urls.py (I am using the
djangoproject.com urls.py as an example.)

Here's some snippets...

from django.conf.urls.defaults import *
from django.contrib.sitemaps import views as sitemap_views
from django.views.decorators.cache import cache_page

urlpatterns = patterns('',
(r'^admin/', include('django.contrib.admin.urls')),
(r'^sitemap.xml$', cache_page(sitemap_views.index, 60 * 60 * 24),
{'sitemaps': my_sitemaps}),
(r'^sitemap-(?P<section>.+).xml$', cache_page(sitemap_views.sitemap,
60 * 60 * 24), {'sitemaps': my_sitemaps}),
)

my_sitemaps is a dictionary of my sitemaps (built following the example
in the Sitemap documentation). With this code I can access the
individual sitemaps without trouble, but can't access the main
sitemap.xml file (that's when I get the "NoReverseMatch at /sitemap.xml"
exception). However, the following code worked for all files:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^admin/', include('django.contrib.admin.urls')),
(r'^sitemap.xml$', 'django.contrib.sitemaps.views.index',
{'sitemaps': my_sitemaps}),
(r'^sitemap-(?P<section>.+).xml$',
'django.contrib.sitemaps.views.sitemap, {'sitemaps': my_sitemaps}),
)

But I can't implement the cache using this method because you can't pass
the string 'django.contrib.sitemaps.views.index' as the first parameter
of cache_page since it's expecting a callable.

Anyone see any reasons that the first snippet of code wouldn't be
working for just the sitemap.xml line?

Thanks,

Jay

Reply all
Reply to author
Forward
0 new messages