本文介绍了Django Sitemaps和“normal”意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我不明白Sitemaps的目的,也许我不明白如何使用Sitemaps。现在我的站点地图包括所有动态创建的页面,如博文。但是如何添加静态页面,如我的索引和联系页面?或者这些视图不应该在站点地图中?我以为 - 所有页面都应该在站点地图上。例如,我如何包括这样的视图

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 the blog posts. But how do I add "static" pages like my index and contact page? Or shouldn't these views be in the sitemap? I thought -all- pages should be on the sitemap. For example, how would I include such view

(r'^contact/', include('contact-recaptcha.urls')),

如果没有queryset?

if there is no queryset?

供参考:

提前感谢!

推荐答案

另一个简单的选择:

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}

我故意省略了 lastmod changefreq ,因为指定不正确/假定的数据更糟不包括它。

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

这篇关于Django Sitemaps和“normal”意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 08:57