Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django type object Http404 has no attribute get

Tags:

python

django

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'
like image 865
elad silver Avatar asked Oct 25 '15 10:10

elad silver


2 Answers

Took me a while to figure out,

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

like image 176
elad silver Avatar answered Nov 13 '22 02:11

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()
like image 45
Happy_Man Avatar answered Nov 13 '22 02:11

Happy_Man