0
私たちはPythonでリクエストパッケージを使用してdjango apiへのポストリクエストを作成しようとしています。pythonでjsonを処理するdjangoでのリクエストと応答
要求:
d = {"key1":"123", "key2":[{"a":"b"},{"c":"d"}]}
response = requests.post("http://127.0.0.1:8000/api/postapi/",data=d)
サーバーの終わりに、私たちは以下のコードを使用してパラメータを取得しようとしています。
def handle_post(request):
if request.method == 'POST':
key1 = request.POST.get('key1', '')
key2 = request.POST.get('key2', '')
print key1,type(key1)
print key2,type(key2)
return JsonResponse({'result': 'success'}, status=200)
私はkey1とkey2の値を取得しようとしています。
予想される出力:
123,<type 'unicode'>
[{"a":"b"},{"c":"d"}], <type 'list'>
実際の出力:
123 <type 'unicode'>
c <type 'unicode'>
はどのように我々はジャンゴで期待される出力を得ることができますか?
key2のgetlistを使用すると、dict全体ではなく[u'a '、u'c']が返されます –
user3351750