Skip to Content
Building RESTful Python Web Services
book

Building RESTful Python Web Services

by Gastón C. Hillar
October 2016
Intermediate to advanced
418 pages
9h 52m
English
Packt Publishing
Content preview from Building RESTful Python Web Services

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 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. ...

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

Hands-On RESTful Python Web Services - Second Edition

Hands-On RESTful Python Web Services - Second Edition

Gastón C. Hillar

Publisher Resources

ISBN: 9781786462251Supplemental Content