如何在Django中创建站点地图索引? [英] How do you create a sitemap index in Django?

查看:42
本文介绍了如何在Django中创建站点地图索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 文档很小,我似乎无法使它正常工作.

The Django documentation is very minimal and I can't seem to get this to work.

目前,我有3个单独的站点地图,我想为它们创建一个站点地图索引:

Currently I have 3 individual sitemaps, and I would like to create a sitemap index for them:

(r'^sitemap1\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps':sitemap1}),
(r'^sitemap2\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps':sitemap2}),
(r'^sitemap3\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps':sitemap3}),

Django文档提到添加以下内容:

The Django documentation mentions adding something along the lines of:

url(r'^sitemap-(?P<section>.+)\.xml$', views.sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap'),

在这种情况下,部分"是什么?以及如何访问该索引文件?它可以下载还是可以通过URL访问?

What is "section" in this case? And how do I access this index file? Is it downloadable or is it accessible via a url?

任何帮助将不胜感激!

修改基本上,我想在Django中完成此操作: https://support.google.com/webmasters/answer/75712

Edit Basically I would like to accomplish this in Django: https://support.google.com/webmasters/answer/75712

推荐答案

如果您为应用程序添加了名称空间(例如 include('myapp.urls',namespace ='myapp'),反转时需要包含名称空间,例如 {%url'myapp:my_url_name'%} reverse('myapp:my_url_name').

If you included the app with a namespace (e.g. include('myapp.urls', namespace='myapp'), then you need to include the namespace when reversing, e.g. {% url 'myapp:my_url_name' %} or reverse('myapp:my_url_name').

url(r'^sitemap-(?P<section>.+)\.xml$', cache_page(86400)(views.sitemap), {'sitemaps': sitemaps}, name='sitemapsname'),
url(r'^sitemap\.xml$', cache_page(86400)(views.index), {'sitemaps': sitemaps, 'sitemap_url_name': 'posts:sitemapsname'}),

注意:帖子:sitemapsname是我的应用

note: posts:sitemapsname is my app

请参阅Django的源代码: https://github.com/django/django/blob/master/django/contrib/sitemaps/views.py

see source code of Django: https://github.com/django/django/blob/master/django/contrib/sitemaps/views.py

这篇关于如何在Django中创建站点地图索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆