在写接口的过程中遇到了一次请求状态码400
原因是用element upload组件上传照片,后端采用flask的时候用request.form读取上传携带的其他参数,
data = request.form
title = data['title']
author = data['author']
content = data['content']
这样获取就会请求报错出现400,此时的data为ImmutableMultiDict
修改:使用to_dict()方法转一下就OK了
data = request.form.to_dict()
title = data['title']
author = data['author']
content = data['content']
顺便记录一下前端使用的时候
<el-upload class="upload-demo"
ref="upload"
action="/api/write/diary"
:on-preview="handlePreview"
:on-remove="handleRemove"
:file-list="fileList"
:auto-upload="false"
:data=filedata>
<el-button slot="trigger"
size="small"
type="primary">选取文件</el-button>
<div slot="tip"
class="el-upload__tip"></div>
</el-upload>