Django,使用POST无法触发view中的函数

前端发送的请求:

this.axios({
    method:'POST',
    url: '/book/register',
    data: {
        'userName': 'test'
    },
    headers: {'Content-Type':'application/x-www-form-urlencoded'}
})
.then(res=> {
    console.log('POST success!' + '\n' + res.data)
})

配置的urls:

path('book/register', views.AddUserInfo, name='AddUserInfo'), 视图中的函数:

def AddUserInfo(request):
    print("POST!")
    return HttpResponse('success')

发送POST请求之后,后端控制台的输出:

[01/Dec/2021 12:23:38] "POST /api/book/register HTTP/1.1" 200 2

没有print,前端也没有获得返回。

设置断点发现根本没有调用目标函数。前端使用GET获取数据一切正常,但POST就出现这种情况,请求大神指导。

评论 0