I made my own 404 handler for the authenticated Django website to avoid information leakage.
def check_logged_in_404(request): """ Custom 404. Show friendly 404 when logged in and redirect to /login when not logged in. """ if request.user.is_authenticated(): return render_to_response('404.html') else: return HttpResponseRedirect('/login')
Functionally, it does exactly what I want. However, the 404 return page has a status of 200, which is correct for the code. But this, obviously, should be 404 return status.
The raise404 function does not work, because if infinite recursion does not end, it returns here and thus leads to the same problem.
I tried HttpResponseNotFound, but this only takes a string as an argument, and not a template that is not related to DRY-ish.
And I manually tried to set the title using
response = render_to_response('404.html') response['Status'] = "Not Found - 404" return response
Then the status header is really set, but the browser still shows 200.
I have no options. Anyone who has clues, please be my hero ... :)
Thanx and welcomes
Gerard.
Change I tried the status field value in all btw types, but no luck :(
GerardJP Nov 28 '09 at 12:56 2009-11-28 12:56
source share