Understanding serializers
By now, we are well versed in the way Django works with data in our application. Broadly, the columns of a database table are defined in a class in models.py
, and when we access a row of the table, we are working with an instance of that class. Ideally, we often just want to pass this object to our frontend application. For example, if we wanted to build a website that displayed a list of books in our Bookr app, we would want to call the title
property of each book instance to know what string to display to the user. However, our frontend application knows nothing about Python and needs to retrieve this data through an HTTP request, which just returns a string in a specific format.
This means that any translation of information between Django and the frontend (via our API) must be done by representing the information in JSON format. JSON objects look similar to a Python dictionary, except there are some extra rules that constrict the exact syntax. In our...