Serializing a list of objects with django-rest-framework

You can simply add many=True for serialising list.

comments = [Comment(email="leila@example.com", content="foo bar"),
            Comment(email="leila1@example.com", content="foo bar 1"),
            Comment(email="leila2@example.com", content="foo bar 2")]
serializer = CommentSerializer(comments, many=True)
serializer.data

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)