[Answered ]-How to list the field names from a Django serializer

1👍

You have to call the methods on an instance of the serializer (not the class itself):

serializer = AccountSerializer()
fields = serializer.get_fields().keys()
👤Sofien

0👍

I have found this one-liner using the serializer class which works fine for me:

fields = AccountSerializer.Meta.fields # return a tuple of strings

As a note: I find the method by SofienM can give more information out of the object.

Leave a comment