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
- Having a separate database for django-admin in django
- Best Practices: How to best implement Rating-Stars in Django Templates
- How to access directory file outside django project?
- Django Testing view template context
- How to write separate views for GET and POST
Source:stackexchange.com