Permalink
Browse files

Merge pull request #1098 from zsiciarz/ticket-16829

Added example of using sitemaps with static views.
  • Loading branch information...
2 parents 753edfa + d77082b commit 886f7cc751523caf335c1d59c3cdcef7950cb923 @mjtamlyn mjtamlyn committed May 19, 2013
Showing with 40 additions and 0 deletions.
  1. +40 −0 docs/ref/contrib/sitemaps.txt
@@ -280,6 +280,46 @@ Here's an example of a :doc:`URLconf </topics/http/urls>` using both::
.. _URLconf: ../url_dispatch/
+Sitemap for static views
+========================
+
+Often you want the search engine crawlers to index views which are neither
+object detail pages nor flatpages. The solution is to explicitly list URL
+names for these views in ``items`` and call
+:func:`~django.core.urlresolvers.reverse` in the ``location`` method of
+the sitemap. For example::
+
+ # sitemaps.py
+ from django.contrib import sitemaps
+ from django.core.urlresolvers import reverse
+
+ class StaticViewSitemap(sitemaps.Sitemap):
+ priority = 0.5
+ changefreq = 'daily'
+
+ def items(self):
+ return ['main', 'about', 'license']
+
+ def location(self, item):
+ return reverse(item)
+
+ # urls.py
+ from django.conf.urls import patterns, url
+ from .sitemaps import StaticViewSitemap
+
+ sitemaps = {
+ 'static': StaticViewSitemap,
+ }
+
+ urlpatterns = patterns('',
+ url(r'^$', 'views.main', name='main'),
+ url(r'^about/$', 'views.about', name='about'),
+ url(r'^license/$', 'views.license', name='license'),
+ # ...
+ url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})
+ )
+
+
Creating a sitemap index
========================

0 comments on commit 886f7cc

Please sign in to comment.