Django custom handler404 shows 404 but gives header 200

后端 未结 6 924
春和景丽
春和景丽 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:09

    You can use render method:

    from django.shortcuts import render
    

    Returns a HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments.

    Uses a RequestContext by default.

    Example:

    return render(request, '404.html', status=404)
    

    And with keywords:

    return render(request, '404.html', {'data': 'some data'}, status=404)
    

提交回复
热议问题