[Answered ]-Python return function error

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.

👤ygneo

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

Leave a comment