9👍
✅
You need to add many=True
in your serializer when initializing with multiple instances.
myname = NameSerializer(names,many=True)
1👍
Firstly, field names should be all lowercase, using underscores instead of camelCase, according to the official document. It’s a convention that we all should follow. ex – first_name and fore_name
And as per your question, you should write
myname = NameSerializer(names, many=True)
in views.py, because you’re trying to serialize multiple objects.
- [Django]-Caught TypeError while rendering: 'BoundField' object is not iterable
- [Django]-Django: how to map the results of a raw sql query to model instances in admin list view?
- [Django]-Tidy up complex URL dispatcher
- [Django]-Allowing both email and username login in Django project
- [Django]-Get local system time in Django
Source:stackexchange.com