如何解决创建了站点地图,但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
机器人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的错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。