Django Rest Framework debug post and put requests

前端 未结 4 1656
迷失自我
迷失自我 2021-02-19 12:02

I use DRF extension to se json list for model, and there i can debug with debug-toolbar that GET request, but how can i debug POST and

4条回答
  •  -上瘾入骨i
    2021-02-19 12:53

    If you need to intercept the request/response and apply your own processing then you can add your custom mixin as described in this answer.

    But in the most trivial scenario, given that you do a test POST request (or PUT), for example, with python requests:

    import requests
    response = requests.post('http://localhost:8000/person', json={"name": "dinsdale"})
    

    Then you can get the error message with

    print(response.text)
    

    In most cases the output will contain the failure reason that you were looking for, e.g. 'age' is required.

    You can also do the same thing with curl from a terminal:

    curl -vv --header "Content-Type: application/json" \
        --request POST \
        --data '{"name":"dinsdale"}' http://localhost:8000/person/
    

提交回复
热议问题