从POST请求中读取数据时遇到了麻烦。
从前端看来一切都很好,但是当我什么都没得到的时候 当试图在后端读取请求数据时。
request.FILES
<MultiValueDict: {}>
request.POST
<QueryDict: {}>
request.body
*** RawPostDataException: You cannot access body after reading from request's data stream
后端视图代码
def upload_file(request):
upload_response = requests.post(requestbuilder.create_request('/files'), files={request.FILES['file']._name:request.FILES['file']}, headers=requestbuilder.MULTIPART_HEADERS)
return HttpResponse(upload_response.json().get('fileUrl'))
ajax call的选项
var options = {
url: "/apps/upload/",
method: 'post',
addRemoveLinks: true,
clickable: false,
maxFiles: config.maxFiles,
minWidth: config.minWidth,
minHeight: config.minHeight,
headers: {
'X-CSRFToken': $("input[name=csrfmiddlewaretoken]").val()
},
}
我完全是空白,任何帮助都将不胜感激。