[Solved]-Where in django is the default 500 traceback rendered so that I can use it to create my own logs?

7๐Ÿ‘

โœ…

The 500 traceback page uses a template string (TECHNICAL_500_TEMPLATE) which is hard coded into django.views.debug. The report is generated by an ExceptionReporter class which is also included in django.views.debug which you should be able to re-purpose for your own log generation.

๐Ÿ‘คMark Lavin

5๐Ÿ‘

If we want to show the exceptions that are generated in your template (500.html) then we could write your own 500 view, grabbing the exception and passing it to your 500 template.

Steps:

In my_app.views.py

import sys
import traceback

from django.http.response import HttpResponseServerError
from django.template import loader
from django.template.context import Context, RequestContext


def custom_500(request):
    t = loader.get_template('500.html')
    type, value, tb = sys.exc_info()
    return HttpResponseServerError(
        t.render(
            Context({
                'exception_value': value,
                'value': type,
                'tb': traceback.format_exception(type, value, tb)
            }, RequestContext(request))
        )
    )

In Main Urls.py

from django.conf.urls.defaults import *
handler500 = 'my_app.views.custom_500'

In Template (500.html)

{{ exception_value }}{{value}}{{tb}}

More about it here: https://docs.djangoproject.com/en/dev/topics/http/views/#the-500-server-error-view

๐Ÿ‘คAvinash Garg

1๐Ÿ‘

Duplicate:
Template does not exist: 500.html

Basically just put a 500.html in your template folder and it will use that.

๐Ÿ‘คMikle

Leave a comment