Django 鹡鸰网站 map

标签 django wagtail

我有一个现有的 Django 站点,我已为其添加了 Wagtail 。我想要 Django 和 Wagtail 网址的站点地图。

我当前的sitemap.py:

class StaticSitemap(sitemaps.Sitemap):
    priority = 0.5
    changefreq = "weekly"
    protocol = "https"

    def items(self):
        return ["public:index", "other pages etc..."]

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

我当前的urls.py:

sitemaps = {"static": StaticSitemap}
path(
    "sitemap.xml",
    sitemap,
    {"sitemaps": sitemaps},
    name="django.contrib.sitemaps.views.sitemap",
),

以上对于标准 Django 站点地图可以正确工作。如何包含 Wagtail 网址?

最佳答案

我假设您的站点地图 View 来自 wagtail.contrib.sitemaps.views (如果您使用 Django 的 View ,则应该切换到 Wagtail 的 View 。

那么您唯一需要做的就是将 Wagtail 的站点地图添加到您的站点地图字典中:

from wagtail.contrib.sitemaps.sitemap_generator import Sitemap

sitemaps = {"static": StaticSitemap, "wagtail": Sitemap}

关于 Django 鹡鸰网站 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57848063/

相关文章:

django - Wagtail - 如何访问 block 内的 StructBlock 类属性

python - 并排排列 Wagtailstream 字段

javascript - Slider FileReader JS 多图上传(递增索引)

Django @login_required 删除 https

python - 使用原始查询插入批量数据django

wagtail - Wagtail 如何处理结构内容?

django - 将 Wagtail 添加到现有 Django 应用程序

wagtail - 列 clean_name 不存在(Wagtail 2.10)

python - 在 Python 3.5 而不是 2.7 上运行 Django 1.9

python - 完整性错误位于/posts/create/18/: Key (group_id)=(18) is not present in table "auth_group"