web/lib/django/views/debug.py
changeset 0 0d40e90630ef
child 29 cc9b7e14412b
equal deleted inserted replaced
-1:000000000000 0:0d40e90630ef
       
     1 import os
       
     2 import re
       
     3 import sys
       
     4 import datetime
       
     5 
       
     6 from django.conf import settings
       
     7 from django.template import Template, Context, TemplateDoesNotExist
       
     8 from django.utils.html import escape
       
     9 from django.utils.importlib import import_module
       
    10 from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
       
    11 from django.utils.encoding import smart_unicode, smart_str
       
    12 
       
    13 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST')
       
    14 
       
    15 def linebreak_iter(template_source):
       
    16     yield 0
       
    17     p = template_source.find('\n')
       
    18     while p >= 0:
       
    19         yield p+1
       
    20         p = template_source.find('\n', p+1)
       
    21     yield len(template_source) + 1
       
    22 
       
    23 def get_safe_settings():
       
    24     "Returns a dictionary of the settings module, with sensitive settings blurred out."
       
    25     settings_dict = {}
       
    26     for k in dir(settings):
       
    27         if k.isupper():
       
    28             if HIDDEN_SETTINGS.search(k):
       
    29                 settings_dict[k] = '********************'
       
    30             else:
       
    31                 settings_dict[k] = getattr(settings, k)
       
    32     return settings_dict
       
    33 
       
    34 def technical_500_response(request, exc_type, exc_value, tb):
       
    35     """
       
    36     Create a technical server error response. The last three arguments are
       
    37     the values returned from sys.exc_info() and friends.
       
    38     """
       
    39     reporter = ExceptionReporter(request, exc_type, exc_value, tb)
       
    40     html = reporter.get_traceback_html()
       
    41     return HttpResponseServerError(html, mimetype='text/html')
       
    42 
       
    43 class ExceptionReporter:
       
    44     """
       
    45     A class to organize and coordinate reporting on exceptions.
       
    46     """
       
    47     def __init__(self, request, exc_type, exc_value, tb):
       
    48         self.request = request
       
    49         self.exc_type = exc_type
       
    50         self.exc_value = exc_value
       
    51         self.tb = tb
       
    52 
       
    53         self.template_info = None
       
    54         self.template_does_not_exist = False
       
    55         self.loader_debug_info = None
       
    56 
       
    57         # Handle deprecated string exceptions
       
    58         if isinstance(self.exc_type, basestring):
       
    59             self.exc_value = Exception('Deprecated String Exception: %r' % self.exc_type)
       
    60             self.exc_type = type(self.exc_value)
       
    61 
       
    62     def get_traceback_html(self):
       
    63         "Return HTML code for traceback."
       
    64 
       
    65         if issubclass(self.exc_type, TemplateDoesNotExist):
       
    66             from django.template.loader import template_source_loaders
       
    67             self.template_does_not_exist = True
       
    68             self.loader_debug_info = []
       
    69             for loader in template_source_loaders:
       
    70                 try:
       
    71                     module = import_module(loader.__module__)
       
    72                     source_list_func = module.get_template_sources
       
    73                     # NOTE: This assumes exc_value is the name of the template that
       
    74                     # the loader attempted to load.
       
    75                     template_list = [{'name': t, 'exists': os.path.exists(t)} \
       
    76                         for t in source_list_func(str(self.exc_value))]
       
    77                 except (ImportError, AttributeError):
       
    78                     template_list = []
       
    79                 self.loader_debug_info.append({
       
    80                     'loader': loader.__module__ + '.' + loader.__name__,
       
    81                     'templates': template_list,
       
    82                 })
       
    83         if settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source'):
       
    84             self.get_template_exception_info()
       
    85 
       
    86         frames = self.get_traceback_frames()
       
    87 
       
    88         unicode_hint = ''
       
    89         if issubclass(self.exc_type, UnicodeError):
       
    90             start = getattr(self.exc_value, 'start', None)
       
    91             end = getattr(self.exc_value, 'end', None)
       
    92             if start is not None and end is not None:
       
    93                 unicode_str = self.exc_value.args[1]
       
    94                 unicode_hint = smart_unicode(unicode_str[max(start-5, 0):min(end+5, len(unicode_str))], 'ascii', errors='replace')
       
    95         from django import get_version
       
    96         t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
       
    97         c = Context({
       
    98             'exception_type': self.exc_type.__name__,
       
    99             'exception_value': smart_unicode(self.exc_value, errors='replace'),
       
   100             'unicode_hint': unicode_hint,
       
   101             'frames': frames,
       
   102             'lastframe': frames[-1],
       
   103             'request': self.request,
       
   104             'settings': get_safe_settings(),
       
   105             'sys_executable': sys.executable,
       
   106             'sys_version_info': '%d.%d.%d' % sys.version_info[0:3],
       
   107             'server_time': datetime.datetime.now(),
       
   108             'django_version_info': get_version(),
       
   109             'sys_path' : sys.path,
       
   110             'template_info': self.template_info,
       
   111             'template_does_not_exist': self.template_does_not_exist,
       
   112             'loader_debug_info': self.loader_debug_info,
       
   113         })
       
   114         return t.render(c)
       
   115 
       
   116     def get_template_exception_info(self):
       
   117         origin, (start, end) = self.exc_value.source
       
   118         template_source = origin.reload()
       
   119         context_lines = 10
       
   120         line = 0
       
   121         upto = 0
       
   122         source_lines = []
       
   123         before = during = after = ""
       
   124         for num, next in enumerate(linebreak_iter(template_source)):
       
   125             if start >= upto and end <= next:
       
   126                 line = num
       
   127                 before = escape(template_source[upto:start])
       
   128                 during = escape(template_source[start:end])
       
   129                 after = escape(template_source[end:next])
       
   130             source_lines.append( (num, escape(template_source[upto:next])) )
       
   131             upto = next
       
   132         total = len(source_lines)
       
   133 
       
   134         top = max(1, line - context_lines)
       
   135         bottom = min(total, line + 1 + context_lines)
       
   136 
       
   137         self.template_info = {
       
   138             'message': self.exc_value.args[0],
       
   139             'source_lines': source_lines[top:bottom],
       
   140             'before': before,
       
   141             'during': during,
       
   142             'after': after,
       
   143             'top': top,
       
   144             'bottom': bottom,
       
   145             'total': total,
       
   146             'line': line,
       
   147             'name': origin.name,
       
   148         }
       
   149 
       
   150     def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, module_name=None):
       
   151         """
       
   152         Returns context_lines before and after lineno from file.
       
   153         Returns (pre_context_lineno, pre_context, context_line, post_context).
       
   154         """
       
   155         source = None
       
   156         if loader is not None and hasattr(loader, "get_source"):
       
   157             source = loader.get_source(module_name)
       
   158             if source is not None:
       
   159                 source = source.splitlines()
       
   160         if source is None:
       
   161             try:
       
   162                 f = open(filename)
       
   163                 try:
       
   164                     source = f.readlines()
       
   165                 finally:
       
   166                     f.close()
       
   167             except (OSError, IOError):
       
   168                 pass
       
   169         if source is None:
       
   170             return None, [], None, []
       
   171 
       
   172         encoding = 'ascii'
       
   173         for line in source[:2]:
       
   174             # File coding may be specified. Match pattern from PEP-263
       
   175             # (http://www.python.org/dev/peps/pep-0263/)
       
   176             match = re.search(r'coding[:=]\s*([-\w.]+)', line)
       
   177             if match:
       
   178                 encoding = match.group(1)
       
   179                 break
       
   180         source = [unicode(sline, encoding, 'replace') for sline in source]
       
   181 
       
   182         lower_bound = max(0, lineno - context_lines)
       
   183         upper_bound = lineno + context_lines
       
   184 
       
   185         pre_context = [line.strip('\n') for line in source[lower_bound:lineno]]
       
   186         context_line = source[lineno].strip('\n')
       
   187         post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]]
       
   188 
       
   189         return lower_bound, pre_context, context_line, post_context
       
   190 
       
   191     def get_traceback_frames(self):
       
   192         frames = []
       
   193         tb = self.tb
       
   194         while tb is not None:
       
   195             # support for __traceback_hide__ which is used by a few libraries
       
   196             # to hide internal frames.
       
   197             if tb.tb_frame.f_locals.get('__traceback_hide__'):
       
   198                 tb = tb.tb_next
       
   199                 continue
       
   200             filename = tb.tb_frame.f_code.co_filename
       
   201             function = tb.tb_frame.f_code.co_name
       
   202             lineno = tb.tb_lineno - 1
       
   203             loader = tb.tb_frame.f_globals.get('__loader__')
       
   204             module_name = tb.tb_frame.f_globals.get('__name__')
       
   205             pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
       
   206             if pre_context_lineno is not None:
       
   207                 frames.append({
       
   208                     'tb': tb,
       
   209                     'filename': filename,
       
   210                     'function': function,
       
   211                     'lineno': lineno + 1,
       
   212                     'vars': tb.tb_frame.f_locals.items(),
       
   213                     'id': id(tb),
       
   214                     'pre_context': pre_context,
       
   215                     'context_line': context_line,
       
   216                     'post_context': post_context,
       
   217                     'pre_context_lineno': pre_context_lineno + 1,
       
   218                 })
       
   219             tb = tb.tb_next
       
   220 
       
   221         if not frames:
       
   222             frames = [{
       
   223                 'filename': '&lt;unknown&gt;',
       
   224                 'function': '?',
       
   225                 'lineno': '?',
       
   226                 'context_line': '???',
       
   227             }]
       
   228 
       
   229         return frames
       
   230 
       
   231     def format_exception(self):
       
   232         """
       
   233         Return the same data as from traceback.format_exception.
       
   234         """
       
   235         import traceback
       
   236         frames = self.get_traceback_frames()
       
   237         tb = [ (f['filename'], f['lineno'], f['function'], f['context_line']) for f in frames ]
       
   238         list = ['Traceback (most recent call last):\n']
       
   239         list += traceback.format_list(tb)
       
   240         list += traceback.format_exception_only(self.exc_type, self.exc_value)
       
   241         return list
       
   242 
       
   243 
       
   244 def technical_404_response(request, exception):
       
   245     "Create a technical 404 error response. The exception should be the Http404."
       
   246     try:
       
   247         tried = exception.args[0]['tried']
       
   248     except (IndexError, TypeError):
       
   249         tried = []
       
   250     else:
       
   251         if not tried:
       
   252             # tried exists but is an empty list. The URLconf must've been empty.
       
   253             return empty_urlconf(request)
       
   254 
       
   255     t = Template(TECHNICAL_404_TEMPLATE, name='Technical 404 template')
       
   256     c = Context({
       
   257         'root_urlconf': settings.ROOT_URLCONF,
       
   258         'request_path': request.path_info[1:], # Trim leading slash
       
   259         'urlpatterns': tried,
       
   260         'reason': smart_str(exception, errors='replace'),
       
   261         'request': request,
       
   262         'settings': get_safe_settings(),
       
   263     })
       
   264     return HttpResponseNotFound(t.render(c), mimetype='text/html')
       
   265 
       
   266 def empty_urlconf(request):
       
   267     "Create an empty URLconf 404 error response."
       
   268     t = Template(EMPTY_URLCONF_TEMPLATE, name='Empty URLConf template')
       
   269     c = Context({
       
   270         'project_name': settings.SETTINGS_MODULE.split('.')[0]
       
   271     })
       
   272     return HttpResponse(t.render(c), mimetype='text/html')
       
   273 
       
   274 #
       
   275 # Templates are embedded in the file so that we know the error handler will
       
   276 # always work even if the template loader is broken.
       
   277 #
       
   278 
       
   279 TECHNICAL_500_TEMPLATE = """
       
   280 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
       
   281 <html lang="en">
       
   282 <head>
       
   283   <meta http-equiv="content-type" content="text/html; charset=utf-8">
       
   284   <meta name="robots" content="NONE,NOARCHIVE">
       
   285   <title>{{ exception_type }} at {{ request.path_info|escape }}</title>
       
   286   <style type="text/css">
       
   287     html * { padding:0; margin:0; }
       
   288     body * { padding:10px 20px; }
       
   289     body * * { padding:0; }
       
   290     body { font:small sans-serif; }
       
   291     body>div { border-bottom:1px solid #ddd; }
       
   292     h1 { font-weight:normal; }
       
   293     h2 { margin-bottom:.8em; }
       
   294     h2 span { font-size:80%; color:#666; font-weight:normal; }
       
   295     h3 { margin:1em 0 .5em 0; }
       
   296     h4 { margin:0 0 .5em 0; font-weight: normal; }
       
   297     table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
       
   298     tbody td, tbody th { vertical-align:top; padding:2px 3px; }
       
   299     thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; }
       
   300     tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
       
   301     table.vars { margin:5px 0 2px 40px; }
       
   302     table.vars td, table.req td { font-family:monospace; }
       
   303     table td.code { width:100%; }
       
   304     table td.code div { overflow:hidden; }
       
   305     table.source th { color:#666; }
       
   306     table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
       
   307     ul.traceback { list-style-type:none; }
       
   308     ul.traceback li.frame { margin-bottom:1em; }
       
   309     div.context { margin: 10px 0; }
       
   310     div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
       
   311     div.context ol li { font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
       
   312     div.context ol.context-line li { color:black; background-color:#ccc; }
       
   313     div.context ol.context-line li span { float: right; }
       
   314     div.commands { margin-left: 40px; }
       
   315     div.commands a { color:black; text-decoration:none; }
       
   316     #summary { background: #ffc; }
       
   317     #summary h2 { font-weight: normal; color: #666; }
       
   318     #explanation { background:#eee; }
       
   319     #template, #template-not-exist { background:#f6f6f6; }
       
   320     #template-not-exist ul { margin: 0 0 0 20px; }
       
   321     #unicode-hint { background:#eee; }
       
   322     #traceback { background:#eee; }
       
   323     #requestinfo { background:#f6f6f6; padding-left:120px; }
       
   324     #summary table { border:none; background:transparent; }
       
   325     #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
       
   326     #requestinfo h3 { margin-bottom:-1em; }
       
   327     .error { background: #ffc; }
       
   328     .specific { color:#cc3300; font-weight:bold; }
       
   329     h2 span.commands { font-size:.7em;}
       
   330     span.commands a:link {color:#5E5694;}
       
   331     pre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }
       
   332   </style>
       
   333   <script type="text/javascript">
       
   334   //<!--
       
   335     function getElementsByClassName(oElm, strTagName, strClassName){
       
   336         // Written by Jonathan Snook, http://www.snook.ca/jon; Add-ons by Robert Nyman, http://www.robertnyman.com
       
   337         var arrElements = (strTagName == "*" && document.all)? document.all :
       
   338         oElm.getElementsByTagName(strTagName);
       
   339         var arrReturnElements = new Array();
       
   340         strClassName = strClassName.replace(/\-/g, "\\-");
       
   341         var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
       
   342         var oElement;
       
   343         for(var i=0; i<arrElements.length; i++){
       
   344             oElement = arrElements[i];
       
   345             if(oRegExp.test(oElement.className)){
       
   346                 arrReturnElements.push(oElement);
       
   347             }
       
   348         }
       
   349         return (arrReturnElements)
       
   350     }
       
   351     function hideAll(elems) {
       
   352       for (var e = 0; e < elems.length; e++) {
       
   353         elems[e].style.display = 'none';
       
   354       }
       
   355     }
       
   356     window.onload = function() {
       
   357       hideAll(getElementsByClassName(document, 'table', 'vars'));
       
   358       hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
       
   359       hideAll(getElementsByClassName(document, 'ol', 'post-context'));
       
   360       hideAll(getElementsByClassName(document, 'div', 'pastebin'));
       
   361     }
       
   362     function toggle() {
       
   363       for (var i = 0; i < arguments.length; i++) {
       
   364         var e = document.getElementById(arguments[i]);
       
   365         if (e) {
       
   366           e.style.display = e.style.display == 'none' ? 'block' : 'none';
       
   367         }
       
   368       }
       
   369       return false;
       
   370     }
       
   371     function varToggle(link, id) {
       
   372       toggle('v' + id);
       
   373       var s = link.getElementsByTagName('span')[0];
       
   374       var uarr = String.fromCharCode(0x25b6);
       
   375       var darr = String.fromCharCode(0x25bc);
       
   376       s.innerHTML = s.innerHTML == uarr ? darr : uarr;
       
   377       return false;
       
   378     }
       
   379     function switchPastebinFriendly(link) {
       
   380       s1 = "Switch to copy-and-paste view";
       
   381       s2 = "Switch back to interactive view";
       
   382       link.innerHTML = link.innerHTML == s1 ? s2 : s1;
       
   383       toggle('browserTraceback', 'pastebinTraceback');
       
   384       return false;
       
   385     }
       
   386     //-->
       
   387   </script>
       
   388 </head>
       
   389 <body>
       
   390 <div id="summary">
       
   391   <h1>{{ exception_type }} at {{ request.path_info|escape }}</h1>
       
   392   <pre class="exception_value">{{ exception_value|escape }}</pre>
       
   393   <table class="meta">
       
   394     <tr>
       
   395       <th>Request Method:</th>
       
   396       <td>{{ request.META.REQUEST_METHOD }}</td>
       
   397     </tr>
       
   398     <tr>
       
   399       <th>Request URL:</th>
       
   400       <td>{{ request.build_absolute_uri|escape }}</td>
       
   401     </tr>
       
   402     <tr>
       
   403       <th>Exception Type:</th>
       
   404       <td>{{ exception_type }}</td>
       
   405     </tr>
       
   406     <tr>
       
   407       <th>Exception Value:</th>
       
   408       <td><pre>{{ exception_value|escape }}</pre></td>
       
   409     </tr>
       
   410     <tr>
       
   411       <th>Exception Location:</th>
       
   412       <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td>
       
   413     </tr>
       
   414     <tr>
       
   415       <th>Python Executable:</th>
       
   416       <td>{{ sys_executable|escape }}</td>
       
   417     </tr>
       
   418     <tr>
       
   419       <th>Python Version:</th>
       
   420       <td>{{ sys_version_info }}</td>
       
   421     </tr>
       
   422     <tr>
       
   423       <th>Python Path:</th>
       
   424       <td>{{ sys_path }}</td>
       
   425     </tr>
       
   426     <tr>
       
   427       <th>Server time:</th>
       
   428       <td>{{server_time|date:"r"}}</td>
       
   429     </tr>
       
   430   </table>
       
   431 </div>
       
   432 {% if unicode_hint %}
       
   433 <div id="unicode-hint">
       
   434     <h2>Unicode error hint</h2>
       
   435     <p>The string that could not be encoded/decoded was: <strong>{{ unicode_hint|escape }}</strong></p>
       
   436 </div>
       
   437 {% endif %}
       
   438 {% if template_does_not_exist %}
       
   439 <div id="template-not-exist">
       
   440     <h2>Template-loader postmortem</h2>
       
   441     {% if loader_debug_info %}
       
   442         <p>Django tried loading these templates, in this order:</p>
       
   443         <ul>
       
   444         {% for loader in loader_debug_info %}
       
   445             <li>Using loader <code>{{ loader.loader }}</code>:
       
   446                 <ul>{% for t in loader.templates %}<li><code>{{ t.name }}</code> (File {% if t.exists %}exists{% else %}does not exist{% endif %})</li>{% endfor %}</ul>
       
   447             </li>
       
   448         {% endfor %}
       
   449         </ul>
       
   450     {% else %}
       
   451         <p>Django couldn't find any templates because your <code>TEMPLATE_LOADERS</code> setting is empty!</p>
       
   452     {% endif %}
       
   453 </div>
       
   454 {% endif %}
       
   455 {% if template_info %}
       
   456 <div id="template">
       
   457    <h2>Template error</h2>
       
   458    <p>In template <code>{{ template_info.name }}</code>, error at line <strong>{{ template_info.line }}</strong></p>
       
   459    <h3>{{ template_info.message }}</h3>
       
   460    <table class="source{% if template_info.top %} cut-top{% endif %}{% ifnotequal template_info.bottom template_info.total %} cut-bottom{% endifnotequal %}">
       
   461    {% for source_line in template_info.source_lines %}
       
   462    {% ifequal source_line.0 template_info.line %}
       
   463        <tr class="error"><th>{{ source_line.0 }}</th>
       
   464        <td>{{ template_info.before }}<span class="specific">{{ template_info.during }}</span>{{ template_info.after }}</td></tr>
       
   465    {% else %}
       
   466       <tr><th>{{ source_line.0 }}</th>
       
   467       <td>{{ source_line.1 }}</td></tr>
       
   468    {% endifequal %}
       
   469    {% endfor %}
       
   470    </table>
       
   471 </div>
       
   472 {% endif %}
       
   473 <div id="traceback">
       
   474   <h2>Traceback <span class="commands"><a href="#" onclick="return switchPastebinFriendly(this);">Switch to copy-and-paste view</a></span></h2>
       
   475   {% autoescape off %}
       
   476   <div id="browserTraceback">
       
   477     <ul class="traceback">
       
   478       {% for frame in frames %}
       
   479         <li class="frame">
       
   480           <code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
       
   481 
       
   482           {% if frame.context_line %}
       
   483             <div class="context" id="c{{ frame.id }}">
       
   484               {% if frame.pre_context %}
       
   485                 <ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">{% for line in frame.pre_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol>
       
   486               {% endif %}
       
   487               <ol start="{{ frame.lineno }}" class="context-line"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol>
       
   488               {% if frame.post_context %}
       
   489                 <ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">{% for line in frame.post_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol>
       
   490               {% endif %}
       
   491             </div>
       
   492           {% endif %}
       
   493 
       
   494           {% if frame.vars %}
       
   495             <div class="commands">
       
   496                 <a href="#" onclick="return varToggle(this, '{{ frame.id }}')"><span>&#x25b6;</span> Local vars</a>
       
   497             </div>
       
   498             <table class="vars" id="v{{ frame.id }}">
       
   499               <thead>
       
   500                 <tr>
       
   501                   <th>Variable</th>
       
   502                   <th>Value</th>
       
   503                 </tr>
       
   504               </thead>
       
   505               <tbody>
       
   506                 {% for var in frame.vars|dictsort:"0" %}
       
   507                   <tr>
       
   508                     <td>{{ var.0|escape }}</td>
       
   509                     <td class="code"><div>{{ var.1|pprint|escape }}</div></td>
       
   510                   </tr>
       
   511                 {% endfor %}
       
   512               </tbody>
       
   513             </table>
       
   514           {% endif %}
       
   515         </li>
       
   516       {% endfor %}
       
   517     </ul>
       
   518   </div>
       
   519   {% endautoescape %}
       
   520   <form action="http://dpaste.com/" name="pasteform" id="pasteform" method="post">
       
   521   <div id="pastebinTraceback" class="pastebin">
       
   522     <input type="hidden" name="language" value="PythonConsole">
       
   523     <input type="hidden" name="title" value="{{ exception_type|escape }} at {{ request.path_info|escape }}">
       
   524     <input type="hidden" name="source" value="Django Dpaste Agent">
       
   525     <input type="hidden" name="poster" value="Django">
       
   526     <textarea name="content" id="traceback_area" cols="140" rows="25">
       
   527 Environment:
       
   528 
       
   529 Request Method: {{ request.META.REQUEST_METHOD }}
       
   530 Request URL: {{ request.build_absolute_uri|escape }}
       
   531 Django Version: {{ django_version_info }}
       
   532 Python Version: {{ sys_version_info }}
       
   533 Installed Applications:
       
   534 {{ settings.INSTALLED_APPS|pprint }}
       
   535 Installed Middleware:
       
   536 {{ settings.MIDDLEWARE_CLASSES|pprint }}
       
   537 
       
   538 {% if template_does_not_exist %}Template Loader Error:
       
   539 {% if loader_debug_info %}Django tried loading these templates, in this order:
       
   540 {% for loader in loader_debug_info %}Using loader {{ loader.loader }}:
       
   541 {% for t in loader.templates %}{{ t.name }} (File {% if t.exists %}exists{% else %}does not exist{% endif %})
       
   542 {% endfor %}{% endfor %}
       
   543 {% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty!
       
   544 {% endif %}
       
   545 {% endif %}{% if template_info %}
       
   546 Template error:
       
   547 In template {{ template_info.name }}, error at line {{ template_info.line }}
       
   548    {{ template_info.message }}{% for source_line in template_info.source_lines %}{% ifequal source_line.0 template_info.line %}
       
   549    {{ source_line.0 }} : {{ template_info.before }} {{ template_info.during }} {{ template_info.after }}
       
   550 {% else %}
       
   551    {{ source_line.0 }} : {{ source_line.1 }}
       
   552 {% endifequal %}{% endfor %}{% endif %}
       
   553 Traceback:
       
   554 {% for frame in frames %}File "{{ frame.filename|escape }}" in {{ frame.function|escape }}
       
   555 {% if frame.context_line %}  {{ frame.lineno }}. {{ frame.context_line|escape }}{% endif %}
       
   556 {% endfor %}
       
   557 Exception Type: {{ exception_type|escape }} at {{ request.path_info|escape }}
       
   558 Exception Value: {{ exception_value|escape }}
       
   559 </textarea>
       
   560   <br><br>
       
   561   <input type="submit" value="Share this traceback on a public Web site">
       
   562   </div>
       
   563 </form>
       
   564 </div>
       
   565 
       
   566 <div id="requestinfo">
       
   567   <h2>Request information</h2>
       
   568 
       
   569   <h3 id="get-info">GET</h3>
       
   570   {% if request.GET %}
       
   571     <table class="req">
       
   572       <thead>
       
   573         <tr>
       
   574           <th>Variable</th>
       
   575           <th>Value</th>
       
   576         </tr>
       
   577       </thead>
       
   578       <tbody>
       
   579         {% for var in request.GET.items %}
       
   580           <tr>
       
   581             <td>{{ var.0 }}</td>
       
   582             <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   583           </tr>
       
   584         {% endfor %}
       
   585       </tbody>
       
   586     </table>
       
   587   {% else %}
       
   588     <p>No GET data</p>
       
   589   {% endif %}
       
   590 
       
   591   <h3 id="post-info">POST</h3>
       
   592   {% if request.POST %}
       
   593     <table class="req">
       
   594       <thead>
       
   595         <tr>
       
   596           <th>Variable</th>
       
   597           <th>Value</th>
       
   598         </tr>
       
   599       </thead>
       
   600       <tbody>
       
   601         {% for var in request.POST.items %}
       
   602           <tr>
       
   603             <td>{{ var.0 }}</td>
       
   604             <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   605           </tr>
       
   606         {% endfor %}
       
   607       </tbody>
       
   608     </table>
       
   609   {% else %}
       
   610     <p>No POST data</p>
       
   611   {% endif %}
       
   612   <h3 id="files-info">FILES</h3>
       
   613   {% if request.FILES %}
       
   614     <table class="req">
       
   615         <thead>
       
   616             <tr>
       
   617                 <th>Variable</th>
       
   618                 <th>Value</th>
       
   619             </tr>
       
   620         </thead>
       
   621         <tbody>
       
   622             {% for var in request.FILES.items %}
       
   623                 <tr>
       
   624                     <td>{{ var.0 }}</td>
       
   625                     <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   626                 </tr>
       
   627             {% endfor %}
       
   628         </tbody>
       
   629     </table>
       
   630   {% else %}
       
   631     <p>No FILES data</p>
       
   632   {% endif %}
       
   633 
       
   634 
       
   635   <h3 id="cookie-info">COOKIES</h3>
       
   636   {% if request.COOKIES %}
       
   637     <table class="req">
       
   638       <thead>
       
   639         <tr>
       
   640           <th>Variable</th>
       
   641           <th>Value</th>
       
   642         </tr>
       
   643       </thead>
       
   644       <tbody>
       
   645         {% for var in request.COOKIES.items %}
       
   646           <tr>
       
   647             <td>{{ var.0 }}</td>
       
   648             <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   649           </tr>
       
   650         {% endfor %}
       
   651       </tbody>
       
   652     </table>
       
   653   {% else %}
       
   654     <p>No cookie data</p>
       
   655   {% endif %}
       
   656 
       
   657   <h3 id="meta-info">META</h3>
       
   658   <table class="req">
       
   659     <thead>
       
   660       <tr>
       
   661         <th>Variable</th>
       
   662         <th>Value</th>
       
   663       </tr>
       
   664     </thead>
       
   665     <tbody>
       
   666       {% for var in request.META.items|dictsort:"0" %}
       
   667         <tr>
       
   668           <td>{{ var.0 }}</td>
       
   669           <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   670         </tr>
       
   671       {% endfor %}
       
   672     </tbody>
       
   673   </table>
       
   674 
       
   675   <h3 id="settings-info">Settings</h3>
       
   676   <h4>Using settings module <code>{{ settings.SETTINGS_MODULE }}</code></h4>
       
   677   <table class="req">
       
   678     <thead>
       
   679       <tr>
       
   680         <th>Setting</th>
       
   681         <th>Value</th>
       
   682       </tr>
       
   683     </thead>
       
   684     <tbody>
       
   685       {% for var in settings.items|dictsort:"0" %}
       
   686         <tr>
       
   687           <td>{{ var.0 }}</td>
       
   688           <td class="code"><div>{{ var.1|pprint }}</div></td>
       
   689         </tr>
       
   690       {% endfor %}
       
   691     </tbody>
       
   692   </table>
       
   693 
       
   694 </div>
       
   695 
       
   696 <div id="explanation">
       
   697   <p>
       
   698     You're seeing this error because you have <code>DEBUG = True</code> in your
       
   699     Django settings file. Change that to <code>False</code>, and Django will
       
   700     display a standard 500 page.
       
   701   </p>
       
   702 </div>
       
   703 </body>
       
   704 </html>
       
   705 """
       
   706 
       
   707 TECHNICAL_404_TEMPLATE = """
       
   708 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
       
   709 <html lang="en">
       
   710 <head>
       
   711   <meta http-equiv="content-type" content="text/html; charset=utf-8">
       
   712   <title>Page not found at {{ request.path_info|escape }}</title>
       
   713   <meta name="robots" content="NONE,NOARCHIVE">
       
   714   <style type="text/css">
       
   715     html * { padding:0; margin:0; }
       
   716     body * { padding:10px 20px; }
       
   717     body * * { padding:0; }
       
   718     body { font:small sans-serif; background:#eee; }
       
   719     body>div { border-bottom:1px solid #ddd; }
       
   720     h1 { font-weight:normal; margin-bottom:.4em; }
       
   721     h1 span { font-size:60%; color:#666; font-weight:normal; }
       
   722     table { border:none; border-collapse: collapse; width:100%; }
       
   723     td, th { vertical-align:top; padding:2px 3px; }
       
   724     th { width:12em; text-align:right; color:#666; padding-right:.5em; }
       
   725     #info { background:#f6f6f6; }
       
   726     #info ol { margin: 0.5em 4em; }
       
   727     #info ol li { font-family: monospace; }
       
   728     #summary { background: #ffc; }
       
   729     #explanation { background:#eee; border-bottom: 0px none; }
       
   730   </style>
       
   731 </head>
       
   732 <body>
       
   733   <div id="summary">
       
   734     <h1>Page not found <span>(404)</span></h1>
       
   735     <table class="meta">
       
   736       <tr>
       
   737         <th>Request Method:</th>
       
   738         <td>{{ request.META.REQUEST_METHOD }}</td>
       
   739       </tr>
       
   740       <tr>
       
   741         <th>Request URL:</th>
       
   742       <td>{{ request.build_absolute_uri|escape }}</td>
       
   743       </tr>
       
   744     </table>
       
   745   </div>
       
   746   <div id="info">
       
   747     {% if urlpatterns %}
       
   748       <p>
       
   749       Using the URLconf defined in <code>{{ settings.ROOT_URLCONF }}</code>,
       
   750       Django tried these URL patterns, in this order:
       
   751       </p>
       
   752       <ol>
       
   753         {% for pattern in urlpatterns %}
       
   754           <li>{{ pattern }}</li>
       
   755         {% endfor %}
       
   756       </ol>
       
   757       <p>The current URL, <code>{{ request_path|escape }}</code>, didn't match any of these.</p>
       
   758     {% else %}
       
   759       <p>{{ reason }}</p>
       
   760     {% endif %}
       
   761   </div>
       
   762 
       
   763   <div id="explanation">
       
   764     <p>
       
   765       You're seeing this error because you have <code>DEBUG = True</code> in
       
   766       your Django settings file. Change that to <code>False</code>, and Django
       
   767       will display a standard 404 page.
       
   768     </p>
       
   769   </div>
       
   770 </body>
       
   771 </html>
       
   772 """
       
   773 
       
   774 EMPTY_URLCONF_TEMPLATE = """
       
   775 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
       
   776 <html lang="en"><head>
       
   777   <meta http-equiv="content-type" content="text/html; charset=utf-8">
       
   778   <meta name="robots" content="NONE,NOARCHIVE"><title>Welcome to Django</title>
       
   779   <style type="text/css">
       
   780     html * { padding:0; margin:0; }
       
   781     body * { padding:10px 20px; }
       
   782     body * * { padding:0; }
       
   783     body { font:small sans-serif; }
       
   784     body>div { border-bottom:1px solid #ddd; }
       
   785     h1 { font-weight:normal; }
       
   786     h2 { margin-bottom:.8em; }
       
   787     h2 span { font-size:80%; color:#666; font-weight:normal; }
       
   788     h3 { margin:1em 0 .5em 0; }
       
   789     h4 { margin:0 0 .5em 0; font-weight: normal; }
       
   790     table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
       
   791     tbody td, tbody th { vertical-align:top; padding:2px 3px; }
       
   792     thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; }
       
   793     tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
       
   794     ul { margin-left: 2em; margin-top: 1em; }
       
   795     #summary { background: #e0ebff; }
       
   796     #summary h2 { font-weight: normal; color: #666; }
       
   797     #explanation { background:#eee; }
       
   798     #instructions { background:#f6f6f6; }
       
   799     #summary table { border:none; background:transparent; }
       
   800   </style>
       
   801 </head>
       
   802 
       
   803 <body>
       
   804 <div id="summary">
       
   805   <h1>It worked!</h1>
       
   806   <h2>Congratulations on your first Django-powered page.</h2>
       
   807 </div>
       
   808 
       
   809 <div id="instructions">
       
   810   <p>Of course, you haven't actually done any work yet. Here's what to do next:</p>
       
   811   <ul>
       
   812     <li>If you plan to use a database, edit the <code>DATABASE_*</code> settings in <code>{{ project_name }}/settings.py</code>.</li>
       
   813     <li>Start your first app by running <code>python {{ project_name }}/manage.py startapp [appname]</code>.</li>
       
   814   </ul>
       
   815 </div>
       
   816 
       
   817 <div id="explanation">
       
   818   <p>
       
   819     You're seeing this message because you have <code>DEBUG = True</code> in your
       
   820     Django settings file and you haven't configured any URLs. Get to work!
       
   821   </p>
       
   822 </div>
       
   823 </body></html>
       
   824 """