Beispiel #1
0
 def get(self, *args, **kwargs):
     stream = io.BytesIO()
     img, code = check_code.create_validate_code()
     img.save(stream, "png")
     self.session["CheckCode"] = code
     print(self.session["CheckCode"])
     self.write(stream.getvalue())
Beispiel #2
0
def check_code(request):
    """
    获取验证码
    :param request:
    :return:
    """
    stream = io.BytesIO()
    img, code = CheckCode.create_validate_code()
    img.save(stream, "png")
    request.session["CheckCode"] = code
    return HttpResponse(stream.getvalue())
def check_code(req):
    '''
    :param req:
    :return: 返回一个验证码
    '''
    stream = io.BytesIO()  # 在内存中开辟一个区域用于存放图片 python3中用BytesIO()
    img, code = CheckCode.create_validate_code(
    )  # 创建一张图片格式的字符串,将随机字符串code写到图片上
    img.save(stream, "PNG")  # 规定好写进内存中的格式是什么
    req.session["CheckCode"] = code  # 将字符串形式的验证码放到Session中
    return HttpResponse(stream.getvalue())
Beispiel #4
0
 def get(self, *args, **kwargs):
     # 创建一个内存级别的容器
     stream = io.BytesIO()
     # 创建图片并写入验证码
     img, code = check_code.create_validate_code()
     # 写入容器
     img.save(stream, "png")
     # 把验证码存入session, 为每个用户保存验证码
     self.session["CheckCode"] = code
     # 将图片内容而不是路径 返回给客户端
     self.write(stream.getvalue())
Beispiel #5
0
def check_code(request):
    """
    获取验证码
    :param request:
    :return:
    """
    stream = io.BytesIO()
    # 创建随机字符 code
    # 创建一张图片格式的字符串,将随机字符串写到图片上
    img, code = CheckCode.create_validate_code()
    img.save(stream, "png")
    # 将字符串形式的验证码放在Session中
    request.session["CheckCode"] = code
    return HttpResponse(stream.getvalue())