Answer the question
In order to leave comments, you need to log in
“This field is required” when sending a POST request to the Django Rest Fremework API, and axios?
I want to send a post request, but for some reason it returns 400 pages to me and the response comes This field is required
post.vue
methods: {
sendMessage () {
let options = {
params: {
title: this.title,
body: this.textField,
article: this.article.id
},
headers: {
'Content-Type': 'application/json'
},
}
HTTP.post('/comments/', options)
.then(response => {
this.$message({
type: 'success',
message: 'Ваше комментарий ждет утверждений'
})
console.log(response)
})
.catch(err => {
console.log(err)
})
},
class CommentsView(viewsets.ModelViewSet):
queryset = Comments.objects.all()
serializer_class = CommentSerializer
Answer the question
In order to leave comments, you need to log in
Solved the problem, it was necessary to put models.py, blank=true, null=true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question