2017-04-19 1 views
1

django rest 프레임 워크와 함께 angullar2를 사용하고 있습니다. 나는 각 클라이언트에서 문자열을 게시하는 것을 시도하고있다 :'str'객체는 호출 할 수 없습니다 django angular2

postAuthCode(code: string) { 
    let headers = new Headers({ 'Content-Type': 'application/json' }); 
    let options = new RequestOptions({ headers: headers }); 

    var body ={ "code" : code}; 

    return this.http 
    .post(this.authCodeUrl, {body},options) 
    .toPromise() 
    .then(res => { 
     console.log("the post response", res); 
       return res ; 
    }) 
    .catch(this.handleError); 
} 

백엔드의 뷰 클래스 : 내가 클라이언트에서 테스트 할 때

class AdwordAuthCode(APIView): 
    def post(self, request, format=None): 

    """ 
    :param request: 
    :param format: 
    :return: the credentials from the recieved code 
    """ 
    data = request.body('code') 

    print('data', data) 

    return Response(data) 

내가

enter image description here

를 얻을 수

답변

2

오류가 발생하면 문자열 인 동안 request.body를 함수로 취급합니다. 답례로 예상되는 500 개의 오류 HTML 페이지가 표시됩니다.

request.body('code')request.data['code']으로 대체해야합니다.

+1

네, 답변 해 주신 데 대해 감사했습니다. – sila

관련 문제