django reqwest post请求 报400 403错误

获取本地cookie本地的 csrftoken 因为django 表单提交需要

#获取csrftoken 的方法
getCookie(name) {

    var value = '; ' + document.cookie;
    var parts = value.split('; ' + name + '=');
    if (parts.length === 2) return parts.pop().split(';').shift()
},

在reqwest请求中 表头输入

 ClassAddData: function () {
                let that = this;
                that.form.isLoading = !that.form.isLoading
                reqwest({
                    url: "http://127.0.0.1:8000/api/student/",
                    type: "json",
                    method: "post",
                    contentType: 'application/json',
                    headers: {
                        "X-CSRFTOKEN": that.getCookie('csrftoken'),
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'Client_ID': 'YXBpLmVmcGVyZmVjdA==',
                        'Client_Secret': 'aVNmVzh3Vk9kM3cxQTh1OQ==',
                    },
                    data: {
                        name: that.form.name,
                        sex: that.form.sex,
                        tel: that.form.tel,
                    },
                    success: function (resp) {
                        console.log(resp);
                        that.form.msg = resp.static
                        that.modelShow()
                    },
                    error: function (err) {
                        console.log(err)
                        that.form.msg = err.static
                        that.form.isLoading = !that.form.isLoading
                    }
                })
            },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值