It is a copy of: is there a way to show the Django debug stacktrace page to admin users even if DEBUG=False in settings? but there is no answer
How to show django error page with stacktrace when debug=False only for admin users. I don't want to use sentry.
I find an answer
In urls.py add
handler404 = 'site_utils.handler404'
Create site_utils.py in the same folder where urls.py and add there
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
import sys
from django.views.debug import technical_404_response, technical_500_response
def handler404(request):
if (request.user.is_active and request.user.is_staff) or request.user.is_superuser:
exc_type, exc_value, tb = sys.exc_info()
return technical_404_response(request, exc_value)
else:
return HttpResponsePermanentRedirect("/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With