OnlineJudge/utils/captcha/views.py

12 lines
295 B
Python
Raw Normal View History

2017-08-18 22:10:48 +00:00
from base64 import b64encode
2015-09-10 07:59:48 +00:00
2017-08-18 22:10:48 +00:00
from . import Captcha
from ..api import APIView
2015-09-10 07:59:48 +00:00
2017-08-18 22:10:48 +00:00
class CaptchaAPIView(APIView):
def get(self, request):
img_prefix = "data:image/png;base64,"
img = img_prefix + b64encode(Captcha(request).get()).decode("utf-8")
return self.success(img)