From 907d40cac424c9c7bf3a190b445858bc6eab949e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 6 Oct 2014 21:48:58 -0400 Subject: [PATCH] Add pretty handler for 404 Signed-off-by: Simo Sorce Reviewed-by: Patrick Uiterwijk --- ipsilon/root.py | 1 + ipsilon/util/errors.py | 7 +++++++ ipsilon/util/page.py | 2 +- templates/notfound.html | 13 +++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 templates/notfound.html diff --git a/ipsilon/root.py b/ipsilon/root.py index 0046ddf..b2654ac 100755 --- a/ipsilon/root.py +++ b/ipsilon/root.py @@ -43,6 +43,7 @@ class Root(Page): # set up error pages cherrypy.config['error_page.400'] = errors.Error_400(self._site) cherrypy.config['error_page.401'] = errors.Error_401(self._site) + cherrypy.config['error_page.404'] = errors.Error_404(self._site) cherrypy.config['error_page.500'] = errors.Errors(self._site) # now set up the default login plugins diff --git a/ipsilon/util/errors.py b/ipsilon/util/errors.py index 3d7ea28..2f3cc3d 100755 --- a/ipsilon/util/errors.py +++ b/ipsilon/util/errors.py @@ -54,3 +54,10 @@ class Error_401(Errors): def handler(self, status, message, traceback, version): return self._error_template('unauthorized.html', title='Unauthorized', message=message) + + +class Error_404(Errors): + + def handler(self, status, message, traceback, version): + return self._error_template('notfound.html', + title='Not Found', message=message) diff --git a/ipsilon/util/page.py b/ipsilon/util/page.py index 1548d47..a99d2f4 100755 --- a/ipsilon/util/page.py +++ b/ipsilon/util/page.py @@ -108,7 +108,7 @@ class Page(Log): return t.render(**m) def default(self, *args, **kwargs): - raise cherrypy.HTTPError(404) + raise cherrypy.NotFound() def add_subtree(self, name, page): self.__dict__[name] = page diff --git a/templates/notfound.html b/templates/notfound.html new file mode 100644 index 0000000..71743b5 --- /dev/null +++ b/templates/notfound.html @@ -0,0 +1,13 @@ +{% extends "master.html" %} +{% block main %} +
+

404 - Not Found

+ {% if message: %} +

{{ message }}

+ {% else %} +

This page does not exist.

+ {% endif %} +

If you think this is an error, contact the server administrator to + resolve the problem.

+
+{% endblock %} -- 2.20.1