Django

Code

Changeset 1233

Show
Ignore:
Timestamp:
11/14/05 11:44:50 (3 years ago)
Author:
jacob
Message:

Added "pretty" error pages to be used when DEBUG is True.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/handlers/base.py

    r1009 r1233  
    8787        except exceptions.Http404, e: 
    8888            if DEBUG: 
    89                 return self.get_technical_error_response(is404=True, exception=e) 
     89                return self.get_technical_error_response(request, is404=True, exception=e) 
    9090            else: 
    9191                callback, param_dict = resolver.resolve404() 
     
    9494            db.db.rollback() 
    9595            if DEBUG: 
    96                 return self.get_technical_error_response(
     96                return self.get_technical_error_response(request
    9797            else: 
    9898                subject = 'Database error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) 
     
    104104        except: # Handle everything else, including SuspiciousOperation, etc. 
    105105            if DEBUG: 
    106                 return self.get_technical_error_response(
     106                return self.get_technical_error_response(request
    107107            else: 
    108108                subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) 
     
    124124        return callback(request, **param_dict) 
    125125 
    126     def get_technical_error_response(self, is404=False, exception=None): 
     126    def get_technical_error_response(self, request, is404=False, exception=None): 
    127127        """ 
    128128        Returns an HttpResponse that displays a TECHNICAL error message for a 
    129129        fundamental database or coding error. 
    130130        """ 
     131        import sys 
     132        from django.views import debug 
    131133        if is404: 
    132             from django.conf.settings import ROOT_URLCONF 
    133             from django.utils.html import escape 
    134             html = ['<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'] 
    135             html.append('<html><head><title>Error 404</title>') 
    136             # Explicitly tell robots not to archive this, in case this slips 
    137             # onto a production site. 
    138             html.append('<meta name="robots" content="NONE,NOARCHIVE" />') 
    139             html.append('</head><body><h1>Error 404</h1>') 
    140             try: 
    141                 tried = exception.args[0]['tried'] 
    142             except (IndexError, TypeError): 
    143                 if exception.args: 
    144                     html.append('<p>%s</p>' % escape(exception.args[0])) 
    145             else: 
    146                 html.append('<p>Using the URLconf defined in <code>%s</code>, Django tried these URL patterns, in this order:</p>' % ROOT_URLCONF) 
    147                 html.append('<ul>%s</ul>' % ''.join(['<li><code>%s</code></li>' % escape(t).replace(' ', '&nbsp;') for t in tried])) 
    148                 html.append("<p>The current URL, <code><strong>%r</strong></code>, didn't match any of these.</p>" % exception.args[0]['path']) 
    149             html.append("<hr /><p>You're seeing this error because you have <code>DEBUG = True</code> in your Django settings file. Change that to <code>False</code>, and Django will display a standard 404 page.</p>") 
    150             html.append('</body></html>') 
    151             return httpwrappers.HttpResponseNotFound('\n'.join(html)) 
     134            return debug.technical_404_response(request, exception) 
    152135        else: 
    153             output = "There's been an error:\n\n%s" % self._get_traceback() 
    154             return httpwrappers.HttpResponseServerError(output, mimetype='text/plain') 
     136            return debug.technical_500_response(request, *sys.exc_info()) 
    155137 
    156138    def _get_traceback(self):