0

I try to create a sitemap index based on the documentation but it fails. It works well when I show two models and my static views inside a single sitemap, despite it's a mess. This is what I have so far.

I create a sitemaps.py.

# sitemaps.py
from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import reverse
from apps.project.models import Project
from django.contrib.auth import get_user_model


class StaticViewSitemap(Sitemap):
    priority = 0.5
    changefreq = 'daily'

    def items(self):
        return [
            'home_app:home',
            'explore_app:explore',
            'customauth_app:login',
            'customauth_app:signup',
            'contact_app:contact',
        ]

    def location(self, item):
        return reverse(item)


class ProjectSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.5

    def items(self):
        return Project.objects.all()


class UserSitemap(Sitemap):
    changefreq = "daily"
    priority = 0.5

    def items(self):
        user = get_user_model()
        return user.objects.all()

My urls are these:

# urls.py
from django.conf.urls import patterns, include, url
from .sitemaps import ProjectSitemap, UserSitemap, StaticViewSitemap


sitemaps = {
    'project': ProjectSitemap,
    'user': UserSitemap,
    'static': StaticViewSitemap,
}

urlpatterns = patterns(
    'django.contrib.sitemaps.views',
    ## This works, but don't create a sitemap index.
    # url(
    #     r'^sitemap\.xml$',
    #     'sitemap',
    #     {'sitemaps': sitemaps},
    #     name='django.contrib.sitemaps.views.sitemap'
    # ),
    url(
        r'^sitemap\.xml$',
        'index',
        {'sitemaps': sitemaps},
    ),
    url(
        r'^sitemap-(?P<section>.+)\.xml$',
        'sitemap',
        {'sitemaps': sitemaps}
    ),
)

The error that I got seems to be related to this line.

django debug error

Thanks for your help.

oskargicast
  • 667
  • 1
  • 7
  • 14

0 Answers0