Skip to Content
Hands-On RESTful Python Web Services - Second Edition
book

Hands-On RESTful Python Web Services - Second Edition

by Gastón C. Hillar
December 2018
Intermediate to advanced
500 pages
12h 33m
English
Packt Publishing
Content preview from Hands-On RESTful Python Web Services - Second Edition

Writing API views

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 views.py file located within the games_service/games folder. 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. 

Replace the existing code with the following lines. The new code creates a JSONResponse class and declares two functions: game_collection and game_detail. 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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building RESTful Python Web Services

Building RESTful Python Web Services

Gastón C. Hillar
Python Command Line Tools

Python Command Line Tools

Alfredo Deza, Noah Gift

Publisher Resources

ISBN: 9781789532227Supplemental Content