dhandapani
dhandapani

Reputation: 13

Python return function error

While running this function to validate captcha key and value i am not able to return it show error like this "AttributeError: 'bool' object has no attribute 'status_code'"

def validate(request):
 id=request.GET.get('id','')
 key=request.GET.get('key','') 
 captchavalue = mc.get(str(id))

 if captchavalue == key:

     return True

 else:

     return False

Upvotes: 1

Views: 2134

Answers (2)

ygneo
ygneo

Reputation: 412

By reading the code and the error, I assume that validate is a view. A view must always return a HttpResponse. So if you want to return a response indicating a boolean value, indicating if captchavalue == key, do:

from django.http import HttpResponse

def validate(request):
 id=request.GET.get('id','')
 key=request.GET.get('key','') 
 captchavalue = mc.get(str(id))

 return HttpResponse(captchavalue == key)

I'm not 100% sure about the import line, but it's something very similar.

Upvotes: 2

Boaz Yaniv
Boaz Yaniv

Reputation: 6424

I don't know much Django, but it seems it expects you to return a response object instead of a bool value (True / False).

Maybe your code should like more like this:

if captchvalue == key:
    return HttpResponse('HTML Page saying OK')
else:
    return HttpResponse('HTML Page saying Error')

Upvotes: 0

Related Questions