Skip to content
Snippets Groups Projects
Commit 97746495 authored by Dorian Lesbre's avatar Dorian Lesbre
Browse files

Added sitemap

parent a4cb9737
No related branches found
No related tags found
No related merge requests found
from django.contrib.sitemaps.views import sitemap
from django.views.generic import RedirectView
from django.urls import path
from . import views
sitemaps = {"static_pages": views.StaticViewSitemap}
urlpatterns = [
path('', views.static_view, {"slug":"home"}, name = 'home'),
path('inscription/', views.static_view, {"slug":"inscription"}, name = 'inscription'),
path('activites/', views.static_view, {"slug":"activites"}, name = 'activites'),
path('faq/', views.static_view, {"slug":"faq"}, name = 'FAQ'),
path('favicon.ico', RedirectView.as_view(url='/static/imgs/favicon.ico')),
path(
'sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'
),
]
\ No newline at end of file
from django.contrib.sitemaps import Sitemap
from django.shortcuts import render
from django.urls import reverse
def static_view(request, slug):
return render(request, slug+'.html', {'slug': slug})
class StaticViewSitemap(Sitemap):
changefreq = 'monthly'
def items(self):
return ["home", "inscription", "activites", "FAQ"]
def location(self, item):
return reverse(item)
def priority(self, obj):
# Priorize home page over the rest in search results
if obj == "home" or obj == "":
return 0.8
else:
return None # defaults to 0.5 when unset
\ No newline at end of file
......@@ -37,7 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home.apps.HomeConfig'
'django.contrib.sitemaps',
'home.apps.HomeConfig',
]
MIDDLEWARE = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment