django type object Http404 has no attribute get

Question:

I have this code:

if not selected_organization in request.user.organizations.all():
        return Http404

while returning the http 404 I got this :

type object 'Http404' has no attribute 'get'
Asked By: elad silver

||

Answers:

Took me a while to figure out,

Eventually I had to raise the Http404 and not return it!

Answered By: elad silver

return Http404() ==> is a wrong

raise Http404() ==> is a correct

((under _ example code))

def room_detail(request, pk):
    try:
        room = models.Room.objects.get(pk=pk)        
        return render(request, "rooms/detail.html", {"room": room})
    except models.Room.DoesNotExist:
        raiseHttp404()
Answered By: Happy_Man
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.