October 2016
Intermediate to advanced
418 pages
9h 52m
English
Now, we will create Django views that will use the previously created GameSerializer class to return JSON representations for each HTTP request that our API will handle. Open the games/views.py file. The following lines show the initial code for this file, with just one import statement and a comment that indicates we should create the views.
from django.shortcuts import render # Create your views here.
The following lines show the new code that creates a JSONResponse class and declares two functions: game_list and game_detail, in the games/views.py file. We are creating our first version of the API, and we use functions to keep the code as simple as possible. We will work with classes and more complex code in the next examples. ...