Django custom handler404 shows 404 but gives header 200

后端 未结 6 923
春和景丽
春和景丽 2020-12-15 11:58

I made a custom handler404 for a authenticated Django website to avoid information leakage.

def check_logged_in_404(request):
    \"\"\" Custom 404. Show fr         


        
6条回答
  •  自闭症患者
    2020-12-15 12:19

    Why don't you just use Http404 exception?

    if request.user.is_authenticated():
        raise Http404
    else:
        return HttpResponseRedirect('/login')
    

    That should be just fine for you.

提交回复
热议问题