How do you extend Django's sitemap module to create more complex sitemaps?
I have a supplier that wants a sitemap that contains much more meta data than what you would see in a normal search engine sitemap. As a result I would like开发者_如何学JAVA find a tidy way of extending django's sitemap module. Has anyone done this? Or could you provide this django Noob with the code to do it?
Mike
If you really wanted to do this you would need to extend django.contrib.sitemaps.Sitemap.get_urls
to add the additional meta information to the url_info
dictionary. The current get_urls
is given below from django.contrib.sitemaps:
def get_urls(self, page=1, site=None):
if site is None:
if Site._meta.installed:
try:
site = Site.objects.get_current()
except Site.DoesNotExist:
pass
if site is None:
raise ImproperlyConfigured("In order to use Sitemaps you must either use the sites framework or pass in a Site or RequestSite object in your view code.")
urls = []
for item in self.paginator.page(page).object_list:
loc = "http://%s%s" % (site.domain, self.__get('location', item))
priority = self.__get('priority', item, None)
url_info = {
'location': loc,
'lastmod': self.__get('lastmod', item, None),
'changefreq': self.__get('changefreq', item, None),
'priority': str(priority is not None and priority or '')
}
urls.append(url_info)
return urls
After that you would need to change django/contrib/sitemaps/templates/sitemap.xml
to include your extra information in the sitemap. Unrelated to Django if you are adding extra meta information you should read up on the sitemaps.org protocol section regarding extending the protocol.
精彩评论