Add a simple sitemap using django.contrib.sitemaps - there aren't a lot of pages to map so far so it's pretty basic ;)

This commit is contained in:
Danielle McLean 2017-10-24 21:14:17 +11:00
parent f5f4a1d03f
commit 501c91bd12
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
3 changed files with 28 additions and 3 deletions

12
home/sitemaps.py Normal file
View file

@ -0,0 +1,12 @@
from django.contrib import sitemaps
from django.urls import reverse
class HomeSitemap(sitemaps.Sitemap):
changefreq = 'daily'
def items(self):
return ('home:index',)
def location(self, item):
return reverse(item)

View file

@ -60,6 +60,7 @@ INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sitemaps',
'django.contrib.messages',
'django.contrib.staticfiles',

View file

@ -16,8 +16,20 @@ Including another URLconf
from django.conf.urls import include, url
from django.contrib import admin
import django.contrib.sitemaps.views as sitemap
from home.sitemaps import HomeSitemap
sections = {
'home': HomeSitemap,
}
maps = {'sitemaps': sections}
urlpatterns = [
url(r'^', include('home.urls')),
url(r'^.well-known/', include('wellknowns.urls')),
url(r'^admin/', admin.site.urls),
url('', include('home.urls')),
url('^.well-known/', include('wellknowns.urls')),
url('^admin/', admin.site.urls),
url(r'^sitemap\.xml$', sitemap.index, maps),
url(r'^sitemaps/(?P<section>.+)\.xml$', sitemap.sitemap, maps,
name='django.contrib.sitemaps.views.sitemap'),
]