How to make a Django Serializer

Photo by Daniel Dara on Unsplash

How to translate django models or objects into any format. Let’s start.

First you have to install django rest framework to use the serializer as follows.

Then add the django rest framework to the installed apps in settings.py.

First let’s make a simple model in models.py

Then let’s create a serialiser which help us to convert data to a format which can be easily rendered into JSON, XML or other content types. Following code is placed in .

In serializer class you can get all the fields by altering or you can get all the fields excluding one fields changing to .

Hopefully this is helpful.

If you have found this helpful please hit that 👏 and share it on social media :).