Our code in the games/views.py
file declared a JSONResponse
class and two function-based views. These functions returned JSONResponse
when it was necessary to return JSON data and a django.Http.Response.HttpResponse
instance when the response was just of an HTTP status code.
No matter the accepted content type specified in the HTTP request header, the view functions always provide the same content in the response body-JSON. Run the following two commands to retrieve all the games with different values for the Accept
request header-text/html
and application/json
:
http :8000/games/ Accept:text/html http :8000/games/ Accept:application/json
The following are the equivalent curl commands:
curl -H 'Accept: text/html' -iX GET :8000/games/ curl -H 'Accept: application/json' -iX GET :8000/games/
The preceding commands will compose and send the following HTTP request: GET http://localhost:8000/games/
. The first command defines the text/html
value for the Accept...