Exemplo n.º 1
0
 def post(self, request):
     image_form = UploadImageForm(request.POST, request.FILES, instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return HttpResponse('{"status":"success"}', content_type='application/json')
     else:
         return HttpResponse('{"status":"fail"}', content_type='application/json')
Exemplo n.º 2
0
 def post(self, request):
     upload_image = UploadImageForm(request.POST,
                                    request.FILES,
                                    instance=request.user)
     if upload_image.is_valid():
         upload_image.save(commit=True)
         return render(request, 'usercenter-info.html')
Exemplo n.º 3
0
 def post(self, request):
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return HttpResponseRedirect(reverse("users:user_info"))
     return HttpResponseRedirect(reverse("users:user_info"))
Exemplo n.º 4
0
 def post(self, request):
     # 把前段传入的数据保存    直接实例化,实例化直接保存
     image_form = UploadImageForm(request.POST, request.FILES, instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return HttpResponseRedirect(reverse("i:info"))
     else:
         return render(request, 'my_info.html')
Exemplo n.º 5
0
 def post(self, request):
     # ModelForm : instance 接收一个已经存在的模型实例;如果提供,save() 将更新这个实例
     image_form = UploadImageForm(request.POST, request.FILES, instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return HttpResponse('{"status":"success"}', content_type="application/json")
     else:
         return HttpResponse('{"status":"fail"}', content_type="application/json")
Exemplo n.º 6
0
 def post(self, request):
     imageForm = UploadImageForm(request.POST,
                                 request.FILES,
                                 instance=request.user)
     if imageForm.is_valid():
         imageForm.save(commit=True)
         return JsonResponse({"status": "success"})
     else:
         return JsonResponse({"status": "fail"})
Exemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return JsonResponse({"status": "success"})
     else:
         return JsonResponse({"status": "fail"})
Exemplo n.º 8
0
 def post(self, request):
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     if image_form.is_valid():
         image_form.save()
         return JsonResponse({'status': 'success'})
     else:
         return JsonResponse({'status': 'fail'})
Exemplo n.º 9
0
    def post(self, request):
        image_form = UploadImageForm(request.POST, request.FILES, instance=request.user)
        if image_form.is_valid():
            image_form.save()

            suc_dict = {'status': 'success'}
            return HttpResponse(json.dumps(suc_dict), content_type="application/json")
        else:
            error_dict = {'status': 'fail', 'msg': u'错误'}
            return HttpResponse(json.dumps(error_dict), content_type="application/json")
Exemplo n.º 10
0
 def post(self, request):
     res = {}
     upload_image = UploadImageForm(request.POST, request.FILES, instance=request.user)
     if upload_image.is_valid():
         upload_image.save()
         res['status'] = 'success'
         return HttpResponse(json.dumps(res), content_type='application/json')
     else:
         res['status'] = 'fail'
         return HttpResponse(json.dumps(res), content_type='application/json')
Exemplo n.º 11
0
 def post(self, request):
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     # 因为继承的是ModelForm,所以直接拥有了Model的属性和方法,直接可以save()
     try:
         image_form.save()
         return HttpResponse(json.dumps({'status': 'success'}),
                             content_type='application/json')
     except:
         return HttpResponse(json.dumps({'status': 'fail'}),
                             content_type='application/json')
Exemplo n.º 12
0
 def post(self, request):
     # 这时候用户上传的文件就已经被保存到imageform了 ,为modelform添加instance值直接保存
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     if image_form.is_valid():
         image_form.save()
         # # 取出cleaned data中的值,一个dict
         # image = image_form.cleaned_data['image']
         # request.user.image = image
         # request.user.save()
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         return HttpResponse('{"status":"fail"}',
                             content_type='application/json')
Exemplo n.º 13
0
 def post(self, request):
     # image_form = UploadImageForm(request.POST, request.FILES)
     # if image_form.is_valid():
     #     image = image_form.cleaned_data['image']
     #     request.user.image = image
     #     request.user.save()
     image_form = UploadImageForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
     res = dict()
     if image_form.is_valid():
         image_form.save()
         res['status'] = 'success'
         res['msg'] = '头像修改成功'
     else:
         res['status'] = 'fail'
         res['msg'] = '头像修改失败'
     return HttpResponse(json.dumps(res), content_type='application/json')
Exemplo n.º 14
0
 def post(self, request):
     image_form = UploadImageForm(
         request.POST,
         request.FILES,
     )
     if image_form.is_valid():
         # form 中保存就能直接更改user头像
         image_form.save()
         # 另一种方法
         # # 取出cleaned data中的值,一个dict
         # image = image_form.cleaned_data['image']
         # request.user.image = image
         # request.user.save()
         return HttpResponse('{"status":"success",}',
                             content_type='application/json')
     else:
         return HttpResponse('{"status": "fail", }',
                             content_type='application/json')
Exemplo n.º 15
0
    def post(self, request):
        # image_form = UploadImageForm(request.POST, request.FILES)
        # if image_form.is_valid():
        #     image = image_form.cleaned_data['image']
        #     request.user.image = image
        #     request.user.save()
        #     pass

        image_form = UploadImageForm(request.POST,
                                     request.FILES,
                                     instance=request.user)
        if image_form.is_valid():
            image_form.save()
            return HttpResponse(json.dumps({"status": "success"}),
                                content_type='application/json')
        else:
            return HttpResponse(json.dumps({"status": "fail"}),
                                content_type='application/json')