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 PUT
requests?
I have this for settings in debug mode:
INSTALLED_APPS += ('debug_toolbar',)
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
DEBUG_TOOLBAR_PATCH_SETTINGS = False
INTERNAL_IPS = (
'127.0.0.1'
)
Now, when i try with Intercept redirects
in debug-toolbar, it doesn't show me toolbar when i do POST
.
Define Django REST framework Routes When a client sends request to our Django Rest Api for an endpoint using HTTP request (GET, POST, PUT, DELETE), we need to determine how the server will response by defining the routes. Create a urls.py inside tutorials app with urlpatterns containing url s to be matched with request functions in the views.py:
Step by step to implement Django Rest Api. 1 1. Technology. 2 2. Project structure. 3 3. Install Django REST framework. 4 4. Setup new Django project. 5 5. Setup new Django app for CRUD Rest Api. More items
Django does not put data sent with a PUT or DELETE request in a request.PUT or request.DELETE dictionary, like it does with GET or POST data. This is for a good reason. What you can do to solve these problems? You can use the so called POST TUNNELLING method, that is using a POST request, putting the HTTP header X_METHODOVERRIDE in the request.
request.stream returns a stream representing the content of the request body. You won't typically need to directly access the request's content, as you'll normally rely on REST framework's default request parsing behavior. As REST framework's Request extends Django's HttpRequest, all the other standard attributes and methods are also available.
I found django-silk
for debugging DRF.
https://github.com/django-silk/silk/
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With