Defining serializers

After setting up REST framework, we need to specify how our data will be serialized. Output data has to be serialized in a specific format, and input data will be de-serialized for processing. The framework provides the following classes to build serializers for single objects:

  • Serializer: Provides serialization for normal Python class instances
  • ModelSerializer: Provides serialization for model instances
  • HyperlinkedModelSerializer: The same as ModelSerializer, but it represents object relationships with links rather than primary keys

Let's build our first serializer. Create the following file structure inside the courses application directory:

api/    __init__.py    serializers.py

We will build all the API functionality inside ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.