And If you have multiples Sitemaps classes you can use a mixin approach.
An example for Django 1.5.1.
from django.contrib.sitemaps import Sitemap
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from yourapp.models import MyObj
class SiteMapDomainMixin(Sitemap):
def get_urls(self, page=1, site=None, protocol=None):
# give a check in https://github.com/django/django/blob/1.5.1/django/contrib/sitemaps/__init__.py
# There's also a "protocol" argument.
fake_site = Site(domain='example.com', name='example.com')
return super(SiteMapDomainMixin, self).get_urls(page, fake_site, protocol=None)
class MySitemap(SiteMapDomainMixin):
changefreq = "never"
priority = 0.5
def items(self):
return MyObj.objects.all().order_by('pk')[:1000]
def location(self, item):
return reverse('url_for_access_myobj', args=(item.slug,))
def lastmod(self, obj):
return obj.updated_at
class AnotherSitemap(Sitemap):
changefreq = "never"
priority = 0.5
def items(self):
return ['url_1', 'url_2', 'url_3',]
def location(self, item):
return reverse(item)
The urls.py
would be something like...
from sitemaps import MySitemap
from sitemaps import AnotherSitemap
from yourapp.views import SomeDetailMyObjView
admin.autodiscover()
sitemaps = {
'mysitemap': MySitemap,
'anothersitemap': AnotherSitemap,
}
urlpatterns = patterns('',
# other urls...
url(r'^accessing-myobj/(?P<myobj_slug>[-\w]+)$', SomeDetailMyObjView, name='url_for_access_myobj'),
(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
)
django.contrib.sites
active? If you do,sitemaps
will take active site from there. – Canulasites
to make it return some fake Site withdomain
which you need. – Canula