def getVCode(request): ''' 点击换一张时生成新的验证码 ''' code_img = yanzhengma.create_validate_code() code_img[0].save("./goup/static/css/validate.png", "PNG") image_data = open("./goup/static/css/validate.png","rb").read() response = HttpResponse(image_data, content_type="image/png") #将验证码存储进session request.session['vcode'] = code_img[1].lower() return response
def validate(request): #try: # import cStringIO as StringIO #except ImportError: import StringIO mstream = StringIO.StringIO() validate_code = create_validate_code() img = validate_code[0] # path1 = "/langman1dian/rte/static/yzmtp/"+str(time.time())+str(random.random())+".png" img.save(mstream,"png") img1 = open('/langman1dian/rte/static/yzmtp/xxx.gif','r') img1 = mstream.getvalue() mstream.close() request.session['validate'] = validate_code[1].upper() return HttpResponse(img1,"image/png")
def index(request): code_img = yanzhengma.create_validate_code() code_img[0].save("./goup/static/css/validate.png", "PNG") return render_to_response('form.html',locals())
def createdream(request): code_img = yanzhengma.create_validate_code() code_img[0].save("./blog/static/css/validate.png", "PNG") return render_to_response('createdream.html',locals())