def registration(request): cletters = random.choice(ascii_lowercase) + random.choice(ascii_lowercase) + random.choice(ascii_lowercase) + random.choice(ascii_lowercase) ckey = str(random.SystemRandom().randrange(0, 18446744073709551616L)) + str(time.time()) key_ = unicodedata.normalize('NFKD', ckey + unicode(cletters.upper())).encode('ascii', 'ignore') + unicodedata.normalize('NFKD', unicode(cletters)).encode('ascii', 'ignore') key = hashlib.sha1(key_).hexdigest() print key print cletters cptmod = Captcha() cptmod.hash = key cptmod.code = cletters cptmod.save() c = { 'key' : key, 'form': RegistrationForm, } return render(request, 'registration.html', c)