'render custom error pages'

def write_error(self, status_code, **kwargs):

    exc_info = kwargs.get('exc_info')
    message = ''
    exception = None
    status_message = responses.get(status_code, 'Unknown    HTTP    Error')
    if exc_info:
        exception = exc_info[1]
        try:
            message = (exception.log_message % exception.args)
        except Exception:
            pass
        reason = getattr(exception, 'reason', '')
        if reason:
            message = reasons.get(reason, reason)
    ns = dict(status_code=status_code, status_message=status_message, message=message, exception=exception)
    self.set_header('Content-Type', 'text/html')
    try:
        html = self.render_template(('%s.html' % status_code), **ns)
    except TemplateNotFound:
        self.log.debug('No    template    for    %d', status_code)
        html = self.render_template('error.html', **ns)
    self.write(html)
