I have a 500.html template which gets loaded whenever my app explodes but I wanted to know if there’s any way I can output the exception’s message in the template?
So if I do this:
raise Exception("You broke it!")
This will load 500.html when the DEBUG flag is set to True but how can I access the exception message in the template? Something like:
{{ exception.message }}
Many thanks.
G
Have a look at this answer:
How do I include a stacktrace in my Django 500.html page?
It’s not good to pass the exception to your template/user as it might show some inside workings that you don’t want available to the outside, but if you really need to, you could write your own 500 view, grabbing the exception and passing it to your 500 template
views.py
somewhere in urls.py
template
more about it here: https://docs.djangoproject.com/en/1.6/topics/http/views/#the-500-server-error-view