#800: Request ability to override default error template (replaces ticket #795)
----------------------------------+-----------------------------------------
Reporter:
scha...@mischko.com | Owner: rdelon
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: CherryPy code | Keywords:
----------------------------------+-----------------------------------------
It would be nice if we could specify a default error template file.
Simply changing _cperror.py lines 276-280 CP_303:
{{{
# Replace the default template with a custom one?
error_page_file = cherrypy.request.error_page.get(code, '')
if error_page_file:
try:
template = file(error_page_file, 'rb').read()
}}}
to this:
{{{
# Replace the default template with a custom one?
error_page_file = cherrypy.request.error_page.get(code, '')
# If there's no custom one for that error number, is there a default?
if not error_page_file:
error_page_file = cherrypy.request.error_page.get(0, '')
if error_page_file:
try:
# If it's a Python file, import everything from it.
if error_page_file.split('.')[-1].lower() == 'py':
exec('from %s import *' % error_page_file.split('.')[0])
if 'kwargs_update' in locals():
kwargs.update(kwargs_update)
# Otherwise, it's just a template in a file.
else:
template = file(error_page_file, 'rb').read()
}}}
Would change things:
* Defining a default error page handler (where N is the error page
number):
* 'error_page.N': 'error_config.py', or
* 'error_page.N': 'error_config.foo'
* If N is 0, the error_page template will be used in place of the built-
in default.
* Custom error pages are imported if they end in ".py". Otherwise they
are read in.
* Imported pages can include a kwargs_udpate dictionary which will be
included in the kwargs, if present.
This is completely backwards compatible.
--
Ticket URL: <
http://www.cherrypy.org/ticket/800>
CherryPy <
http://www.cherrypy.org>
CherryPy - a pythonic, object-oriented HTTP framework