Add a redirect to entry permalink pages, to ensure entries are only ever accessed at their canonical URL

This commit is contained in:
Danielle McLean 2017-10-27 16:23:31 +11:00
parent 9bd6bc3d1c
commit ecdd63b9d7
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5

View file

@ -1,4 +1,4 @@
from django.shortcuts import render from django.shortcuts import redirect, render
from .models import Entry from .models import Entry
@ -12,6 +12,8 @@ def index(request, kind):
def entry(request, id, slug=None): def entry(request, id, slug=None):
entry = Entry.objects.get(pk=id) entry = Entry.objects.get(pk=id)
if request.path != entry.url:
return redirect(entry.url, permanent=True)
return render(request, 'entries/entry.html', { return render(request, 'entries/entry.html', {
'entry': entry, 'entry': entry,
'title': entry.name or entry.content, 'title': entry.name or entry.content,