Search code examples
djangodjango-cms

Custom Error Pages for django-cms


Supposedly a trivial task to server 403/404/500 error pages when using django-cms. Followed instructions on an old forum post to create this:

from cms.views import details

def custom_404(request):
    response = details(request, 'page-not-found')
    response.status_code = 404
    return response
...

Urls.py has some lines like this:

handler404 = 'error_pages.views.custom_404'
...

From traceback django cms can't locate 404 page:

File "/home/username/.virtualenvs/venv/lib/python2.7/site-packages/cms/views.py", line 22, in _handle_no_page
    raise Http404('CMS: Page not found for "%s"' % slug)

Http404: CMS: Page not found for "page-not-found"

Obviously added the required custom pages in django-cms with the slug: 'page-not-found'. Am I missing something obvious? Running on production server with debug=False. Running django-cms 2.4.2 (edit)

Perhaps it is better to just serve plain ol' error messages with hardcoded stylesheets?


Solution

  • After walking into countless walls over-thinking the issues, I just went with using the basic 403/404/500 handlers:

    from django.utils.functional import curry
    from django.views.defaults import *
    handler500 = curry(server_error, template_name='500.html')
    handler404 = curry(page_not_found, template_name='404.html')
    handler403 = curry(permission_denied, template_name='403.html')
    

    Created the templates for each error and put in absolute URLs for the stylesheets.

    Problem solved. Wasted a bunch of time on something this trivial.