Ejemplo n.º 1
0
 def post(self, request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return HttpResponse('{"status":"success","msg":"修改成功"}',
                             content_type='application/json')
     else:
         return HttpResponse(json.dumps(user_info_form.errors),
                             content_type='application/json')
Ejemplo n.º 2
0
 def post(self, request):
     userInfo_form = UserInfoForm(request.POST, instance=request.user)
     if userInfo_form.is_valid():
         userInfo_form.save()
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         return HttpResponse('{"status":"failure"}',
                             content_type='application/json')
Ejemplo n.º 3
0
 def post(self, request):
     # 不像用户咨询是一个新的。需要指明instance。不然无法修改,而是新增用户
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         # 通过json的dumps方法把字典转换为json字符串
         return HttpResponse(json.dumps(user_info_form.errors),
                             content_type='application/json')
Ejemplo n.º 4
0
    def post(self, request):
        user_info_form = UserInfoForm(request.POST, instance=request.user)
        res = dict()

        if user_info_form.is_valid():
            user_info_form.save()
            res['status'] = 'success'

        else:
            res = user_info_form.errors

        return HttpResponse(json.dumps(res), content_type='application/json')
Ejemplo n.º 5
0
 def post(request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         print('保存成功')
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         print('保存失败')
         print(user_info_form.errors)
         return HttpResponse(json.dumps(user_info_form.errors),
                             content_type='application/json')
Ejemplo n.º 6
0
    def post(self, request):
        # 1、获取前端传递的表单数据
        data = request.POST
        user = request.user
        # 2、验证表单数据
        userinfo_form = UserInfoForm(data)
        res = userinfo_form.is_valid()  # 验证成功返回True,验证失败返回False

        if res:
            # 验证成功,则执行相应业务逻辑操作,这里就直接返回验证成功后的字段数据
            userinfo_data = userinfo_form.cleaned_data
            try:
                UserProfile.objects.filter(pk=user.id).update(**userinfo_data)
            except Exception as e:
                return http.JsonResponse({"status": "error"})
            else:
                return http.JsonResponse({"status": "success"})
Ejemplo n.º 7
0
 def post(self, request):
     # 需要知名instance,不然不知道给谁修改
     user_info_from = UserInfoForm(request.POST, instance=request.user)
     if user_info_from.is_valid():
         user_info_from.save()
Ejemplo n.º 8
0
 def post(self, request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         pass