misc: use page with slug 404 for 404 error pages (#22764)

This commit is contained in:
Frédéric Péters 2018-06-08 12:54:30 +02:00
parent d0b5ca950a
commit 2ffdb41f93
2 changed files with 14 additions and 3 deletions

View File

@ -408,10 +408,15 @@ def error404(request, *args, **kwargs):
# when the given hostname doesn't exist as a tenant
from django.views.defaults import page_not_found
return page_not_found(request, *args, **kwargs)
page = Page()
page.template_name = 'standard'
return publish_page(request, page, status=404, template_name='combo/404.html')
try:
page = Page.objects.get(slug='404')
template_name = None
except Page.DoesNotExist:
page = Page()
page.template_name = 'standard'
template_name = 'combo/404.html'
return publish_page(request, page, status=404, template_name=template_name)
def menu_badges(request):
context = {'request': request}

View File

@ -267,6 +267,12 @@ def test_404(app):
resp = app.get('/foobar/', status=404)
assert "This page doesn't exist" in resp.body
page = Page(title='Not Found', slug='404', template_name='standard')
page.save()
TextCell(page=page, placeholder='content', text='Custom 404 Text', order=0).save()
resp = app.get('/foobar/', status=404)
assert 'Custom 404 Text' in resp.body
def test_style_demo(app, admin_user):
TextCell.objects.all().delete()
Page.objects.all().delete()