1

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
2
  • Where is status_code in your code excerpt? Commented May 9, 2011 at 18:03
  • 1
    Views are supposed to return HttpResponse objects, not booleans. What exactly is the problem you're trying to solve. Commented May 9, 2011 at 18:10

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.