1

在升级到 Wagtail 2.4 之前,我曾经有一个工作站点地图。我已经根据这里的文档升级了我的网站:http: //docs.wagtail.io/en/v2.4/reference/contrib/sitemaps.html但仍然没有这样的运气。我得到的错误是get_sitemap_urls() takes 1 positional argument but 2 were given.

我已添加'django.contrib.sitemaps',到我INSTALLED_APPS的基本设置中,并且我已将以下内容添加到我的urls.py

from wagtail.contrib.sitemaps.views import sitemap

urlpatterns = [
    ...

    url('^sitemap\.xml$', sitemap),

    ...
]

我的页面模型包含以下内容:

def get_sitemap_urls(self, request=None):
        return [
            {
                'location': self.get_full_url(request),
                'lastmod': (self.last_published_at or self.latest_revision_created_at),
                'changefreq': 'monthly',
                'priority': .5,
            }
        ]

我以前包含一个 sitemap.xml 文件来覆盖旧的文件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>

追溯:

django_1    | Traceback (most recent call last):
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
django_1    |     response = get_response(request)
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
django_1    |     response = self.process_exception_by_middleware(e, request)
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
django_1    |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
django_1    |   File "/usr/local/lib/python3.6/site-packages/wagtail/contrib/sitemaps/views.py", line 17, in sitemap
django_1    |     return sitemap_views.sitemap(request, sitemaps, **kwargs)
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/views.py", line 16, in inner
django_1    |     response = func(request, *args, **kwargs)
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/views.py", line 71, in sitemap
django_1    |     protocol=req_protocol))
django_1    |   File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.py", line 111, in get_urls
django_1    |     urls = self._urls(page, protocol, domain)
django_1    |   File "/usr/local/lib/python3.6/site-packages/wagtail/contrib/sitemaps/sitemap_generator.py", line 42, in _urls
django_1    |     url_info_items = item.get_sitemap_urls(self.request)
django_1    | TypeError: get_sitemap_urls() takes 1 positional argument but 2 were given
django_1    | [27/Mar/2019 20:26:13] "GET /sitemap.xml HTTP/1.1" 500 91336

知道我错过了什么吗?我已经完成了文档所说的所有事情,而且非常基础。除了这些步骤之外,我在网上找不到任何其他内容。

4

1 回答 1

0

尝试这个:

def get_sitemap_urls(self, obj):
    return obj.last_published_at
于 2020-10-15T03:18:37.523 回答