-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hi:
I wanted to build a create comment API, Can you tell me why the following error occurs?
I need help, thank you!
HTTP 400 Bad Request
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept
{
"friend": [
"Incorrect type. Expected json encoded string value, received str."
]
}
curl -X POST -H "Content-Type: application/json" -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Im15c3lkbmV5bWFybGluQGdtYWlsLmNvbSIsImV4cCI6MTUwMjA5NDgxNywiZW1haWwiOiJteXN5ZG5leW1hcmxpbkBnbWFpbC5jb20iLCJvcmlnX2lhdCI6MTUwMjA5NDUxN30.YdErA8yXvsJD590OmL65XZj8OY_Pb-kSRBWhlC7s0v8" -d '{
"comment": "Test",
"friend": "p7dvdkcokzksrdx5e4epmomnpq"
}' http://localhost:8000/api/comment/create/
model.py:
comment = models.CharField(max_length=30, verbose_name='Title')
owner = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE, verbose_name='Owner', related_name='owner')
friend = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE, verbose_name='friend', related_name='friend')
serializer.py
class CommentCreateSerializer(EncryptedLookupModelSerializer):
class Meta:
model = Title
fields = ('id', 'comment', 'owner', 'friend')
views.py
class CommentCreateAPIView(CreateAPIView):
serializer_class = CommentCreateSerializer
permissions_classes = [IsAuthenticated]
def perform_create(self, serializer):
serializer.save(manager=self.request.user)