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

In serializer class you can get all the fields by altering fields = '__all__' or you can get all the fields excluding one fields changing fields to exclude = ['email'] .

Hopefully this is helpful.

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

--

--

Technical Writer | Tech Enthusiast | Open source contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store