2017-01-05 5 views
0

오류 "error_message"가 표시됩니다. "int 10 진법이 잘못되었습니다 :" ' " 패치 요청에 대해 사용자 리소스에이 오류가 발생합니다. 내 사용자 모델은django tastypie 패치가 "500"오류를 나타냅니다.

class User(AbstractBaseUser): 

    VIA_FACEBOOK = 1 
    VIA_GOOGLE = 2 

    SIGN_IN_TYPES = (
     (VIA_FACEBOOK,'facebook'), 
     (VIA_GOOGLE,'google') 
    ) 

    MALE = 1 
    FEMALE = 0 

    GENDERA_TYPES = (
     (FEMALE,'female'), 
     (MALE,'male') 
     ) 

    SINGLE_ACCOUNT_USER = 0 
    JOINT_ACCOUNT_USER = 1 


    USER_TYPES = (
     (SINGLE_ACCOUNT_USER,'single_accout_user'), 
     (JOINT_ACCOUNT_USER,'joint_accout_user') 

    ) 
    first_name = models.CharField(blank = True, max_length=50) 
    middle_name = models.CharField(blank=True, max_length=50,null=True) 
    last_name = models.CharField(blank=True, max_length=50,null=True) 
    email = models.EmailField(blank=False,unique=True,max_length=100) 
    sign_in_via = models.SmallIntegerField(choices=SIGN_IN_TYPES, default=0) 
    mobile = models.CharField(blank=True, max_length=10,null=True) 
    dob = models.DateField(blank=True, null=True) 
    profile_pic_url = models.CharField(blank=True,max_length=300,null=True) 
    background_pic_url = models.CharField(blank=True,max_length=300,null=True) 
    gender = models.SmallIntegerField(blank=True,choices=GENDERA_TYPES,null=True) 
    user_type = models.SmallIntegerField(blank=False,choices=USER_TYPES,default=0) 
    details = models.CharField(blank=True,max_length=500,null=True) 
    created_on = models.DateTimeField(auto_now=True) 
    slug = models.SlugField(default='') 

    USERNAME_FIELD = 'email' 

MY 사용자 자원 스크립트입니다 :

class UserResource(ModelResource): 
    class Meta: 
     queryset = User.objects.all() 
     resource_name = 'user' 
     list_allowed_methods = ['get', 'post', 'patch', 'put','delete'] 
     authorization = Authorization() 
     include_resource_uri = True 
     always_return_data = True 
     authentication = Authentication() 
     filtering = { 
      'id': ALL, 
      'email': ALL, 
      'user_type': ALL, 
      'mobile': ALL, 
      'created_at': ALL, 
     } 
     excludes = ['created_on','password','last_login','sign_in_via'] 

GET 및 POST 잘 작동하지만, PATCH 및 PUT 방법이 작동하지 않습니다. 내가 패치 요청하므로 이죠 사용 요청을하고 (http://127.0.0.1:8888/api/user_api/user/14/?format=json) 본체 것이다

{ 
    "background_pic_url": "h/h", 
    "last_name":"sdfsd" 
} 

다음 내가 500을 얻고, 내부 서버 오류. 스택 추적

{ 
    "error_message": "invalid literal for int() with base 10: ''", 
    "traceback": "Traceback (most recent call last): 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 220, in wrapper 
    response = callback(request, *args, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 460, in dispatch_detail 
    return self.dispatch('detail', request, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 483, in dispatch 
    response = method(request, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 1669, in patch_detail 
    bundle = self.full_dehydrate(bundle) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 885, in full_dehydrate 
    data[field_name] = field_object.dehydrate(bundle, for_list=for_list) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\fields.py\", line 146, in dehydrate 
    return self.convert(current_object) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\fields.py\", line 255, in convert 
    return int(value)\n\nValueError: invalid literal for int() with base 10: ''" 

} 

하고 PUT 요청에 대해, 몸이 또한 내가 무엇입니까 500 내부 서버 오류에 대한

{ 
    "email":"[email protected]", 
    "first_name":"a", 
    "middle_name":"b", 
    "last_name":"c", 
    "mobile":"1234567890", 
    "details":"nothing", 
    "profile_pic_url":"n/n", 
    "background_pic_url":"v/v", 
    "sign_in_via":"1", 
    "dob":"2017-01-29", 
    "user_type":"1", 
    "gender":"2" 
} 

될 것입니다. 스택 추적은 다음과 같습니다.

{ 
    "error_message": "'dict' object has no attribute 'first_name'", 
    "traceback": "Traceback (most recent call last): 

    File  \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 220, in wrapper 
    response = callback(request, *args, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 460, in dispatch_detail 
    return self.dispatch('detail', request, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 483, in dispatch 
    response = method(request, **kwargs) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 1472, in put_detail 
    updated_bundle = self.obj_update(bundle=bundle, **self.remove_api_resource_names(kwargs)) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 2226, in obj_update 
    bundle = self.full_hydrate(bundle) 

    File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 939, in full_hydrate 
    setattr(bundle.obj, field_object.attribute, value)\n\nAttributeError: 'dict' object has no attribute 'first_name'" 

} 

이러한 오류가 발생하는 이유는 무엇인지 알 수 없습니다.

{ 
    ... 
    "user_type": "1", 
    "gender": "2" 
} 

및 모델 필드 :

+0

tastypie, PUT, PATCH, GET, POST를 사용하는 메신저에는 코드가 필요 없기 때문에 requsest – Juggernaut

+0

헤이 @AminEtesamian을 처리하는 컨트롤러의 코드를 보여줍니다. 자원은 이러한 요청을 자동으로 처리합니다. 이러한 요청에 대해 도우미 메서드를 사용하지 않습니다. – hemanth5636

답변

1

귀하의 PUT의 몸이 당신이 모델에 지정된처럼

gender = models.SmallIntegerField(blank=True,choices=GENDERA_TYPES,null=True) 
user_type = models.SmallIntegerField(blank=False,choices=USER_TYPES,default=0) 

그래서 당신은 너무 숫자와 PUT/PATCH 요청을해야합니다

{ 
    ... 
    "user_type": 1, 
    "gender": 2 
} 

은 JSON에서 유효합니다.

희망이 도움이됩니다.

감사합니다.