Django Sitemaps and “normal” views

后端 未结 2 1344
长发绾君心
长发绾君心 2021-01-30 11:34

Maybe I didn\'t understand the purpose of Sitemaps or maybe I didn\'t understand how to use sitemaps. Right now my sitemap is including all \"dynamically\" created pages, like t

2条回答
  •  半阙折子戏
    2021-01-30 12:26

    Another simpler alternative:

    from django.core.urlresolvers import reverse
    from django.contrib.sitemaps import Sitemap
    
    
    class ViewSitemap(Sitemap):
        """Reverse 'static' views for XML sitemap."""
    
        def items(self):
            # Return list of url names for views to include in sitemap
            return ['homepage', 'news_article_list', 'contact_page']
    
        def location(self, item):
            return reverse(item)
    
    
    sitemaps = {'views': ViewSitemap}
    

    I've deliberately omitted lastmod and changefreq, as specifying incorrect/assumed data is worse than not including it.

提交回复
热议问题