views.py 704 B

123456789101112131415161718192021222324
  1. # -*-coding:utf-8 -*-
  2. import traceback
  3. from django.views.decorators.csrf import csrf_exempt
  4. from common import JsonResponse,params,save_bs64img_local
  5. # Create your views here.
  6. @csrf_exempt
  7. @params
  8. def upload_img(request):
  9. req_params = request.PARAMS
  10. if req_params:
  11. try:
  12. img_data = req_params.get("img_data")
  13. img_url = save_bs64img_local(img_data)
  14. if img_url:
  15. return JsonResponse({"code": 0, "img_url":img_url})
  16. else:
  17. return JsonResponse({"code": -1,"msg":u"图片上传失败!"})
  18. except:
  19. traceback.print_exc()
  20. else:
  21. return JsonResponse({"code": -1, "msg": u"缺少参数"})