I want to set a variable: correct_captcha, in if statement and return it from the function to HTML, the views is as below:
def list(request):
correct_captcha = None
if request.method == 'POST':
file = request.FILES.get('file', False)
ca_mode = request.POST.get('mode', 'word').lower()
assert ca_mode in ['number', 'word', 'four_number']
captcha = request.POST.get('captcha')
ca = Captcha(request)
if ca.validate(captcha):
if 'file' in request.FILES:
fs = FileSystemStorage()
fs.save('(' + datetime.now().strftime('%Y-%m-%d-%H-%M-%S') +
')' + file.name, file)
filesname= str('(' + datetime.now().strftime('%Y-%m-%d-%H-
%M-%S') + ')' + file.name)
else:
filesname = ''
add_obj = enquiry(file=filesname)
add_obj.save()
correct_captcha = 0
return correct_captcha
else:
correct_captcha = 1
return correct_captcha
return render(request, 'list.html', {'correct_captcha':correct_captcha})
But it did not work, how can I do to return this variable in function?