これは次のコピーです: 設定で DEBUG=False の場合でも、Django デバッグ スタック トレース ページを管理者ユーザーに表示する方法はありますか? しかし、答えはありません
管理者ユーザーに対してのみ debug=False の場合に、スタック トレースを使用して django エラー ページを表示する方法。私は歩哨を使いたくない。
これは次のコピーです: 設定で DEBUG=False の場合でも、Django デバッグ スタック トレース ページを管理者ユーザーに表示する方法はありますか? しかし、答えはありません
管理者ユーザーに対してのみ debug=False の場合に、スタック トレースを使用して django エラー ページを表示する方法。私は歩哨を使いたくない。
私は答えを見つける
urls.py に追加
handler404 = 'site_utils.handler404'
urls.py と同じフォルダーに site_utils.py を作成し、そこに追加します。
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("/")