Ejemplo n.º 1
0
def getcaptcha(request):
    image = ImageCaptcha()
    rand_code = random.sample(string.ascii_letters + string.digits, 1)
    rand_code = "".join(rand_code)
    request.session['code'] = rand_code
    data = image.generate(rand_code)
    return HttpResponse(data, 'image/png')
Ejemplo n.º 2
0
def getcaptcha(request):
    image = ImageCaptcha()
    codes = random.sample(string.ascii_letters + string.digits, 4)
    codes = "".join(codes)
    print(codes)
    request.session['codes'] = codes
    data = image.generate(codes)
    # print(data)
    return HttpResponse(data, 'image/png')
Ejemplo n.º 3
0
def getcaptcha(request):
    image = ImageCaptcha()
    # image =ImageCaptcha(fonts=[os.path.abspath(("DroidSansMono.ttf"))])
    rand_code = random.sample(
        string.ascii_lowercase + string.ascii_uppercase + string.digits, 5)
    rand_code = "".join(rand_code)
    print(rand_code)
    request.session["code"] = rand_code
    data = image.generate(rand_code)
    return HttpResponse(data, "image/png")
Ejemplo n.º 4
0
def getcaptcha(request):
    # 生成一个图片验证码的对象
    image = ImageCaptcha()
    # 生成随机数
    code = random.sample(string.ascii_letters + string.digits, 5)
    code = "".join(code)
    print(code)
    request.session["code"] = code
    data = image.generate(code)
    return HttpResponse(data, "image/png")
Ejemplo n.º 5
0
def getcaptcha(request):
    # 为验证码设置字体 获取当前目录下的xxx目录下的segoesc.ttf文件
    image = ImageCaptcha(fonts=[os.path.abspath("xxx/segoesc.ttf")])
    # 随机码
    # 大小写英文字母+数字,随机抽取5位作为验证码
    code = random.sample(string.ascii_lowercase + string.ascii_uppercase + string.digits, 5)
    # 将验证码存入session,以备后续验证
    random_code = "".join(code)
    request.session['code'] = random_code
    # 将生成的随机字符拼接成字符串,作为验证码图片中的文本
    data = image.generate(random_code)
    # 写出验证图片 给客户端
    return HttpResponse(data, "image/png")
Ejemplo n.º 6
0
def getcaptcha(request):
    try:
        with transaction.atomic():
            image = ImageCaptcha()
            random_code = random.sample(string.ascii_letters + string.digits,
                                        5)
            random_code = "".join(random_code)
            print(random_code)
            request.session["number"] = random_code
            data = image.generate(random_code)

            return HttpResponse(data, "image/png")
    except:
        return HttpResponse("请重试")
Ejemplo n.º 7
0
def getcaptcha(request):
    # 生成一个图片验证码的对象
    image = ImageCaptcha()
    # print(image)
    # 生成随机数
    code = random.sample(string.ascii_letters + string.digits, 1)
    # 把获取的列表进行字符串拼接
    code = "".join(code)
    # print(code)
    # 把你的字符串放入session中  ,方便进行验证
    request.session["code"] = code
    # 把验证码放入你的图片里
    data = image.generate(code)
    # 把验证码图片返回到html界面
    return HttpResponse(data, "image/png")