2015-02-02 3 views
1

어떻게 안드로이드 폼 (get 메소드로)에서 장고 파이썬 서버로 전송 된 JSON 객체의 데이터를 읽습니까?django에서 json 데이터를 읽는 방법?

나는 해봤이

def post_article(sample):  #sample is the http request 
    json = sample.read() 
    data = json.loads(json) 
    a = data['title'] 
    response_data = {} 
    response_data['title'] = a 
    return HttpResponse(json.dumps(response_data), content_type="application/json") 

내이 같은를 사용하여

답변

2

당신은 지역 변수와 json 모듈을 미행하는 작업 확인하는대로 그냥 요청의 내용을 반환하고 이름 대신 다른 변수 이름을 사용해보십시오.

def post_article(sample):  #sample is the http request 
    json_data = sample.read() 
    data = json.loads(json_data) 
    a = data['title'] 
    response_data = {} 
    response_data['title'] = a 
    return HttpResponse(json.dumps(response_data), content_type="application/json") 
+0

다른 변수 이름을 사용하면 작동하지 않습니다. –

+0

@ParitoshWalvekar 무엇이 오류입니까? – GP89

+0

IT 부서에 500 오류가 발생했습니다. 인터넷 서버 오류. –

관련 문제