Download:
child 41:8d6436a284d2
parent 39:81920cb8753b
40:8f08809cc1ce
Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 00:04:48 +0800
viewer: templates for 404 and 500 error pages

3 файлов изменено, 42 вставок(+), 0 удалений(-) [+]
templates/404.html file | annotate | diff | comparison | revisions
templates/500.html file | annotate | diff | comparison | revisions
viewer.py file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/404.html Sun Jun 19 00:04:48 2016 +0800
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block title %}{{ message }}{% end %}
+
+{% block content %}
+ <div class="uk-container uk-container-center uk-margin-large-top">
+ <h1>{{ code }}</h1>
+ <h3>{{ message }}</h3>
+ {% if debug_message %}
+ <pre>{{ debug_message }}</pre>
+ {% end %}
+ </div>
+{% end %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/500.html Sun Jun 19 00:04:48 2016 +0800
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block title %}{{ message }}{% end %}
+
+{% block content %}
+ <div class="uk-container uk-container-center uk-margin-large-top">
+ <h1>{{ code }}</h1>
+ <h3>{{ message }}</h3>
+ {% if debug_message %}
+ <pre>{{ debug_message }}</pre>
+ {% end %}
+ </div>
+{% end %}
--- a/viewer.py Sat Jun 18 22:45:43 2016 +0800
+++ b/viewer.py Sun Jun 19 00:04:48 2016 +0800
@@ -3,6 +3,7 @@
import logging
import os
+import traceback
from peewee import DoesNotExist
from tornado.escape import json_decode
@@ -39,6 +40,21 @@
if not database.is_closed():
database.close()
+ def write_error(self, status_code, **kwargs):
+ data = {
+ 'code': status_code,
+ 'message': self._reason,
+ 'debug_message': ''
+ }
+ if 'exc_info' in kwargs:
+ if self.settings.get('serve_traceback'):
+ fexc = traceback.format_exception(*kwargs['exc_info'])
+ data['debug_message'] = '\n'.join(fexc)
+ if status_code == 404:
+ self.render('404.html', **data)
+ else:
+ self.render('500.html', **data)
+
class IndexHandler(BaseHandler):
def get(self):