创建了站点地图,但Google无法获取错误

问题描述

在Django中,我为我的项目创建了一个站点地图。我没有使用内置的Django Sitemap框架。我创建了一个视图和模板,并从urls.py指向它。当我在资源管理器中打开它时,站点地图可以正常工作。但是,当我将站点地图添加到我的searh控制台时,谷歌给我无法获取错误

无法找出问题所在。有想法吗?

我的观点:

class SitemapPost(ListView):

    model = Movies
    ordering = ['-pk']
    template_name = "front/sitemap-post.xml"
    content_type='application/xml'


    def get_context_data(self,**kwargs):
        context = super().get_context_data(**kwargs)
        today = datetime.Now()
        context['today'] = datetime.Now()
        return context

网址:

path('sitemap-post.xml',SitemapPost.as_view(),name='sitemap-post'),

模板:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  {% for object in object_list %}
  <url>
    <loc>https://{{request.get_host}}{{ object.get_absolute_url }}</loc>
    <lastmod>{{today|date:"Y-m-d"}}</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.9</priority>
  </url>
{% endfor %}
</urlset>

这是我的站点地图文件link

enter image description here

机器人Txt:

Sitemap: https://olefilm.icu/sitemap-post.xml
User-Agent: *
disallow: /headoffice/
disallow: /admin/
disallow: /accounts/login/

解决方法

为什么不使用Django Sitemap框架?这很好。无论如何,请尝试将其添加到您的robots.txt文件

Sitemap: linkToSitemap

User-agent: Googlebot
Disallow:

User-agent: AdsBot-Google
Disallow:

User-agent: Googlebot-Image
Disallow:

这可让Google抓取您的网站,因为某些服务器会自动将其阻止。如果还没有,请确保将其添加到您的网址中

path('robots.txt',TemplateView.as_view(template_name="robots.txt",content_type="text/plain"),),
,

已解决**

我更改了域名,然后重试。有效。 我认为这是Search Console的错误。