J
J
Joirvy2019-03-02 15:49:37
Django
Joirvy, 2019-03-02 15:49:37

How to get data from vue.js in django?

I am a complete newbie to working with server and databases. My task is to send an array from vue app to django server.
I have an array send function (not sure if it's written correctly).

sendResult: function() {
      const xhr = new XMLHttpRequest();
      xhr.open('POST', '/someroute', true);
      xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
      xhr.setRequestHeader('Content-Type', 'application/json');
      xhr.send(JSON.stringify(this.userAnswers));
    },

It is not entirely clear to me which path to specify when sending to the local server and how to accept this data and write it to the model.
I also created a model in models.py
from django.db import models
# Create your models here.
class EnglishTest(models.Model):
    user_id = models.IntegerField()
    test_num = models.IntegerField()
    test_result = models.IntegerField()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-03-02
@sim3x

DRF - для одного запроса слишком жирно
Изучите как на джанге делается вью для приема пост запросов
https://docs.djangoproject.com/en/2.1/intro/tutorial04/
axios - тут вообще непонятно зачем

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question