Вопрос

I have created a sitemap index for my Django site, since I have more than 50k URLs. Django says that it automatically paginates this for me, but I can't access the result in the URL.

Relevant code:

#urls.py
...
sitemaps = {
    'state': StateSitemap,
    'school': SchoolSitemap,
}

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

The sitemap for "state" works just fine:

  • www.example.com/sitemap-state.xml

However for school, which has 100k+ entries, and thus should be automatically paginated by Django, all of the following 404:

  • www.example.com/sitemap-school.xml
  • www.example.com/sitemap-school1.xml
  • www.example.com/sitemap-school/1.xml

I know I'm misunderstanding how ".+" works as part of the sitemap index URL, but I'm stumped.

Which URL should I use to see the paginated sitemap result for "school" in my URL?

Это было полезно?

Решение

You're missing a \ in your url.

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

should be

url(r'^sitemap-(?P<section>.+)\.xml$','django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top