【Vue+django】 配合rest_framework的惊天大坑

我TM一直用vue的post提交数据,一直403,然后测试了N种方法,最后居然是被rest_rest_framework的认证系统 给坑惨了,我没定义认证,它却自动的给我默认上拒绝了


setting配置:

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": [],DEFAULT_PERMISSION_CLASSES
接口文件:
from rest_framework.views import APIView
from django.shortcuts  render,redirect,HttpResponse
from api  models
from django.http  JsonResponse


class Register(APIView):

    def get(self,request):
        return render(request,login.html)

     post(self,request):
        username = str(request.data.get(register_username))
        password = str(request.data.get(register_password))
        message = {}
        try:
            models.UserInfo.objects.create(username=username,password=password)
            message['code'] = 200
            message[message'] = 注册成功"
            return HttpResponse(message)
        except Exception as e:
            message['] = 444注册失败return JsonResponse(message)
vue 文件:
 // 注册
            register() {
                if (this.register_password != this.register_password_re) {
                    alert(两次输入的密码不一致)
                } else if (this.register_username === "" || this.register_password === "" || this.register_password_re === "") {
                    alert(输入框不能为空else {
                    axios.post(/register/',{
                        register_username: this.register_username,register_password: this.register_password
                    })
                        .then(response => {
                        if (response.data['] ==200) {
                            console.log(response.data)
                            alert()
                        } '] == 444) {
                            alert(用户名已存在)
                        }
                    }).catch(error => {
                        console.log(error)
                        alert(请求异常)
                    })
                }
            },

 

相关文章

https://segmentfault.com/a/1190000022018995 https://www....
ES6 (ECMAScript 6)中的模块是一个包含 JavaScript 代码的...
from https://mp.weixin.qq.com/s/-rc1lYYlsfx-wR4mQmIIQQ V...
D:\Temp>npm init vite@latest vue3study --temp...
文章浏览阅读1.2k次。最近自己从零撸起的甘特图组件需要子组...
文章浏览阅读3.3k次,点赞3次,收藏16次。静默打印是什么?简...