用Django在做前后端分离时
接收HTML+jquary+AJAX 前端传来的json数据使用的是:request.POST.get('键名')
def select(request):
日期 = request.POST.get('日期')
。。。。。。。。。过程省略
ret_list = dictfetchall(cur)
return JsonResponse(ret_list, safe=False)
我查到接收VUE+axios前端传来的json数据使用的是:
def select(request):
postBody = request.body
json_result = json.loads(postBody)
print(json_result)
print(json_result['time'])
return JsonResponse({'name': time})
现在想实现VUE+axios前端传来的json数据在Django使用request.POST.get('键名')方式接收,应该怎样处理前端?
前端axios部分代码如下:
axios({
url: '/api/select/',
method: 'post',
data: { time:'2022-11-05' },
}).then((res) => {
this.name = res.name
})
已经自行解决,相关链接:https://blog.csdn.net/m0_56118578/article/details/128327973?spm=1001.2014.3001.5501
一样的吧,post参数都是用那种方式获取