3
我試圖創建一個包含'changefreq'和'優先'的自定義W site站點地圖。默認值只是'lastmod'和'url'。自定義W Sitemap網站地圖
根據鶺鴒文檔(http://docs.wagtail.io/en/latest/reference/contrib/sitemaps.html)您可以通過在/wagtailsitemaps/sitemap.xml
我已經這樣做了建立網站地圖覆蓋默認模板。站點地圖模板看起來是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% spaceless %}
{% for url in urlset %}
<url>
<loc>{{ url.location }}</loc>
{% if url.lastmod %}<lastmod>{{ url.lastmod|date:"Y-m-d" }} </lastmod>{% endif %}
{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %}
{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %}
</url>
{% endfor %}
{% endspaceless %}
</urlset>
我已經加入「wagtail.contrib.wagtailsitemaps」,在設置我安裝的應用。我修改了我的Page類以包含get_sitemap_urls函數,試圖覆蓋它。
class BlockPage(Page):
author = models.CharField(max_length=255)
date = models.DateField("Post date")
body = StreamField([
('heading', blocks.CharBlock(classname='full title')),
('paragraph', blocks.RichTextBlock()),
('html', blocks.RawHTMLBlock()),
('image', ImageChooserBlock()),
])
search_fields = Page.search_fields + (
index.SearchField('heading', partial_match=True),
index.SearchField('paragraph', partial_match=True),
)
content_panels = Page.content_panels + [
FieldPanel('author'),
FieldPanel('date'),
StreamFieldPanel('body'),
]
def get_sitemap_urls(self):
return [
{
'location': self.full_url,
'lastmod': self.latest_revision_created_at,
'changefreq': 'monthly',
'priority': .5
}
]
它仍然無法正常工作。我錯過了別的嗎? W doc文檔不提供關於W is很輕的網頁上的更多信息和其他文檔。任何幫助,將不勝感激。