Changeset 1233
- Timestamp:
- 11/14/05 11:44:50 (3 years ago)
- Files:
-
- django/trunk/django/core/handlers/base.py (modified) (4 diffs)
- django/trunk/django/views/debug.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/handlers/base.py
r1009 r1233 87 87 except exceptions.Http404, e: 88 88 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) 90 90 else: 91 91 callback, param_dict = resolver.resolve404() … … 94 94 db.db.rollback() 95 95 if DEBUG: 96 return self.get_technical_error_response( )96 return self.get_technical_error_response(request) 97 97 else: 98 98 subject = 'Database error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) … … 104 104 except: # Handle everything else, including SuspiciousOperation, etc. 105 105 if DEBUG: 106 return self.get_technical_error_response( )106 return self.get_technical_error_response(request) 107 107 else: 108 108 subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) … … 124 124 return callback(request, **param_dict) 125 125 126 def get_technical_error_response(self, is404=False, exception=None):126 def get_technical_error_response(self, request, is404=False, exception=None): 127 127 """ 128 128 Returns an HttpResponse that displays a TECHNICAL error message for a 129 129 fundamental database or coding error. 130 130 """ 131 import sys 132 from django.views import debug 131 133 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(' ', ' ') 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) 152 135 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()) 155 137 156 138 def _get_traceback(self):
