Catch error text in custom 500 handler

前端 未结 1 1754
梦谈多话
梦谈多话 2021-01-21 03:11

Somewhere in my views, I throw an error, particularly this one:

views.py

from xmlrpclib import Fault

def some_function(request):
    if         


        
1条回答
  •  孤城傲影
    2021-01-21 03:23

    Try to override django.conf.urls.defaults.handler500 in your urls.py.

    from django.conf.urls.defaults import *
    handler500 = 'path.to.my_custom_500'
    

    or even better - write your own handler and put it in the LOGGING settings.

    Edit:

    You can also add to your my_custom_500 code that will recognize type of exception, eg:

    import sys; 
    
    def my_custom_500(request):
        ...
        type_, value, traceback = sys.exc_info()
        ...
    

    0 讨论(0)
提交回复
热议问题