Ticket #10841: better_ajax_500_2.diff

File better_ajax_500_2.diff, 4.3 KB (added by Michail Sychev <overkrik@…>, 16 years ago)

turned off autoescaping for some fields

  • django/views/debug.py

     
    9393                unicode_str = self.exc_value.args[1]
    9494                unicode_hint = smart_unicode(unicode_str[max(start-5, 0):min(end+5, len(unicode_str))], 'ascii', errors='replace')
    9595        from django import get_version
    96         t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
     96        if self.request.is_ajax():
     97            t = Template(TECHNICAL_500_TEMPLATE_AJAX, name='Technical 500 template')
     98        else:   
     99            t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
    97100        c = Context({
    98101            'exception_type': self.exc_type.__name__,
    99102            'exception_value': smart_unicode(self.exc_value, errors='replace'),
     
    278281# always work even if the template loader is broken.
    279282#
    280283
     284TECHNICAL_500_TEMPLATE_AJAX = """
     285
     286{{ exception_type }} at {{ request.path_info|escape }}
     287{% autoescape off %}{{ exception_value }}{% endautoescape %}
     288
     289Request Method: {{ request.META.REQUEST_METHOD }}
     290Request URL: {{ request_protocol }}://{{ request.META.HTTP_HOST }}{{ request.path_info|escape }}
     291
     292Server time: {{server_time|date:"r"}}
     293Django Version: {{ django_version_info }}
     294Python Version: {{ sys_version_info }}
     295Python Path: {% autoescape off %}{{ sys_path }}{% endautoescape %}
     296Python Executable: {{ sys_executable|escape }}
     297Installed Applications:
     298{% autoescape off %}{{ settings.INSTALLED_APPS|pprint }}{% endautoescape %}
     299Installed Middleware:
     300{% autoescape off %}{{ settings.MIDDLEWARE_CLASSES|pprint }}{% endautoescape %}
     301
     302{% if template_does_not_exist %}Template Loader Error:
     303{% if loader_debug_info %}Django tried loading these templates, in this order:
     304{% for loader in loader_debug_info %}Using loader {{ loader.loader }}:
     305{% for t in loader.templates %}{{ t.name }} (File {% if t.exists %}exists{% else %}does not exist{% endif %})
     306{% endfor %}{% endfor %}
     307{% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty!
     308{% endif %}
     309{% endif %}{% if template_info %}
     310Template error:
     311In template {{ template_info.name }}, error at line {{ template_info.line }}
     312   {{ template_info.message }}{% for source_line in template_info.source_lines %}{% ifequal source_line.0 template_info.line %}
     313   {{ source_line.0 }} : {{ template_info.before }} {{ template_info.during }} {{ template_info.after }}
     314{% else %}
     315   {{ source_line.0 }} : {{ source_line.1 }}
     316{% endifequal %}{% endfor %}{% endif %}
     317Traceback:
     318{% for frame in frames %}File "{{ frame.filename|escape }}" in {{ frame.function|escape }}
     319{% if frame.context_line %}  {{ frame.lineno }}. {{ frame.context_line|escape }}{% endif %}
     320{% endfor %}
     321Exception Type: {% autoescape off %}{{ exception_type }} at {{ request.path_info }}{% endautoescape %}
     322Exception Value: {% autoescape off %}{{ exception_value }}{% endautoescape %}
     323
     324Request information:
     325GET:{% if request.GET %}{% for var in request.GET.items %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     326{% endfor %}
     327{% else %} No GET data
     328{% endif %}
     329
     330POST:{% if request.POST %}
     331{% for var in request.POST.items %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     332{% endfor %}
     333{% else %} No POST data
     334{% endif %}
     335 
     336FILES:{% if request.FILES %}
     337{% for var in request.FILES.items %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     338{% endfor %}
     339{% else %} No FILES data
     340{% endif %}
     341
     342COOKIES:{% if request.COOKIES %}
     343{% for var in request.COOKIES.items %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     344{% endfor %}
     345{% else %} No cookie data
     346{% endif %}
     347
     348META:
     349{% for var in request.META.items|dictsort:"0" %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     350{% endfor %}
     351 
     352Settings:
     353Using settings module {{ settings.SETTINGS_MODULE }}
     354{% for var in settings.items|dictsort:"0" %}{% autoescape off %}{{ var.0 }} = {{ var.1 }}{% endautoescape %}
     355{% endfor %}
     356
     357    You're seeing this error because you have DEBUG = True in your
     358    Django settings file. Change that to False, and Django will
     359    display a standard 500 page.
     360
     361"""
     362
    281363TECHNICAL_500_TEMPLATE = """
    282364<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    283365<html lang="en">
Back to Top