L
L
Little Vasya2018-04-26 18:36:33
Vue.js
Little Vasya, 2018-04-26 18:36:33

“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)
          })
      },

views.py
class CommentsView(viewsets.ModelViewSet):
    queryset = Comments.objects.all()
    serializer_class = CommentSerializer

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-04-26
@kentuck1213

https://translate.google.com/#en/ru/This%20field%2...

K
Konstantin Malyarov, 2018-04-26
@Konstantin18ko

How is your model made?

L
Little Vasya, 2018-04-26
@emilov

Solved the problem, it was necessary to put models.py, blank=true, null=true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question