Django request Post json

后端 未结 4 2084
孤独总比滥情好
孤独总比滥情好 2021-01-01 19:35

I try to test a view, I receive a json request from the IPad, the format is:

req = {\"custom_decks\": [
        {
            \"deck_name\": \"deck_test\",
          


        
4条回答
  •  天涯浪人
    2021-01-01 19:51

    python 3.6 and django 2.0 :

    post_json = json.loads(request.body)
    custom_decks = post_json.get("custom_decks")
    

    json.loads(s, *, encoding=None,...)

    Changed in version 3.6: s can now be of type bytes or bytearray. The input encoding should be UTF-8, UTF-16 or UTF-32.

    From python 3.6 NO need request.body.decode('utf-8') .

提交回复
热议问题