Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对django站点地图中的项目列表进行不同的更改频率和优先级?_Django_Xml Sitemap - Fatal编程技术网

如何对django站点地图中的项目列表进行不同的更改频率和优先级?

如何对django站点地图中的项目列表进行不同的更改频率和优先级?,django,xml-sitemap,Django,Xml Sitemap,我在django项目中构建了一个静态站点地图,如下所示: class StaticViewSitemap(Sitemap): changefreq = "weekly" priority = 0.9 protocol = 'http' if DEBUG else 'https' def items(self): return ['home', 'contact_us', 'blog', ] def location(

我在django项目中构建了一个静态站点地图,如下所示:

class StaticViewSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9
    protocol = 'http' if DEBUG else 'https'

    def items(self):
        return ['home', 'contact_us', 'blog', ]

    def location(self, item):
        return reverse(item)
如果我想为不同的URL设置不同的优先级和更改频率,我应该怎么做

我看到了这个问题,但我仍然不知道该怎么办:

以类似的方式,您可以使用:

class StaticViewSitemap(Sitemap):
    changefreq = "weekly"
    # Remove the priority from here
    protocol = 'http' if DEBUG else 'https'

    def items(self):
        return ['home', 'contact_us', 'blog', ]

    def location(self, item):
        return reverse(item)

    def priority(self, item):
        return {'home': 1.0, 'contact_us': 1.0, 'blog': 0.5}[item]

实际上,我是这样做的:

class StaticViewSitemap(Sitemap):

    protocol = 'http' if DEBUG else 'https'
    static_url_list = [
        {'url': 'home', 'priority': 0.8, 'changefreq': "monthly"},
        {'url': 'contact_us', 'priority': 0.6, 'changefreq': "weekly"},
        {'url': 'blog', 'priority': 0.4, 'changefreq': "weekly"}
    ]

    def items(self):
        return [item['url'] for item in self.static_url_list]

    def location(self, item):
        return reverse(item)

    def priority(self, item):
        return {element['url']: element['priority'] for element in self.static_url_list}[item]

    def changefreq(self, item):
        return {element['url']: element['changefreq'] for element in self.static_url_list}[item]