Fix in error template

This commit is contained in:
Antonio de la Rosa 2025-04-11 01:33:31 +02:00
parent c34ab254ed
commit 9a98c4623f
2 changed files with 54 additions and 7 deletions

View file

@ -1,6 +1,6 @@
import os, sys, traceback, inspect, resource
from importlib import import_module
from bottle import route, get, post, run, default_app, abort, request, response, static_file, load, hook, error, debug, redirect
from bottle import route, get, post, run, default_app, abort, request, response, static_file, load, hook, error, debug, redirect, template
from settings import config
#from beaker.middleware import SessionMiddleware
from mimetypes import guess_type
@ -204,7 +204,54 @@ if config.yes_static==True:
else:
mimetype=guess_type(path_module+'/'+filename)
return static_file(filename, root=path_module, mimetype=mimetype[0])
def error_handler_500(e):
tpl_error="""
%try:
%from bottle import DEBUG, request
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>Error: {{e.status}}</title>
<style type="text/css">
html {background-color: #e8eff0; font-family: sans;}
body {background-color: #fbfbfb; border: 1px solid #ddd;
padding: 15px; margin: 15px;}
pre {background-color: #e0f6fa; border: 1px solid #ddd; padding: 5px;}
</style>
</head>
<body>
<h1>Error: {{e.status}}</h1>
<p>Sorry, the requested URL <tt>{{repr(request.url)}}</tt>
caused an error:</p>
<pre>{{e.body}}</pre>
%if DEBUG and e.exception:
<h2>Exception:</h2>
%try:
%exc = repr(e.exception)
%except:
%exc = '<unprintable %s object>' % type(e.exception).__name__
%end
<pre>{{exc}}</pre>
%end
%if DEBUG and e.traceback:
<h2>Traceback:</h2>
<pre>{{e.traceback}}</pre>
%end
</body>
</html>
%except ImportError:
<b>ImportError:</b> Could not generate the error page. Please add bottle to
the import path.
%end
"""
return template(tpl_error, e=e)
app.error(code=500, callback=error_handler_500)
def run_app(app):
if config.server_used!='cherrypy':
run(app=app, host=config.host, server=config.server_used, port=config.port, debug=config.debug, reloader=config.reloader)

View file

@ -58,11 +58,6 @@ admin_folder='/admin'
if hasattr(config, 'admin_folder'):
admin_folder=config.admin_folder
@app.get(admin_folder)
def redirect_home():
redirect(app.get_url('admin_app.home_admin'))
@admin_app.get('/home', name="admin_app.home_admin")
def home_admin(session={}):
@ -73,6 +68,10 @@ def home_admin(session={}):
return t.load_template('layout.phtml', title=_('Admin'), module_selected='home_admin', session=session)
#return {}
@app.get(admin_folder)
def redirect_home():
redirect(app.get_url('admin_app.home_admin'))
@admin_app.get('/login', name="admin_app.login_admin", skip=[check_login])
def login_admin(session={}):
@ -211,6 +210,7 @@ def check_login_admin(session={}):
modules_priv+=v[2]
modules_priv.append('admin_app.home_admin')
modules_priv.append('admin_app.change_theme')
db.query('update useradmin2 set token_login=%s, last_login=%s, token_auth=%s WHERE id=%s', [remember_key, date_now, usermodel.fields['password'].check(token_auth), result['id']])