- from django.http import HttpResponse
- from rest_framework.views import APIView
- # Create your views here.
-
- from libs.captcha.captcha import captcha
-
- '''
- 图片验证
- 1.第三方插件 captcha
- '''
- class ImageCodeView(APIView):
- # 图片验证码
- def get(self,request,image_code_id):
- # 获取图片的验证码
- # 1.调用图片模块 接收图片验证码和图片对象
- text,image = captcha.generate_captcha()
- # 2.保存这个图片验证码的真实值
- # redis_conn = get_redis_connection('verify_codes')
- # redis_conn.setex("img_%s" % image_code_id, constants.IMAGE_CODE_REDIS_EXPIRES, text)
- return HttpResponse(image,content_type="image/png")
re_path(r'^image_codes/(?P[\w-]+)/$', views.ImageCodeView.as_view()), # 图片验证码 /image_codes/ebeed853-1e7b-4b04-a426-3962608cd87f/
