I am trying to upload file. the abnormal is 'The method is not allowed for the requested URL' after run . However my code is request methods is 'POST'
这是我的HTML:
<form action="" enctype='multipart/form-data' method="POST">
<span class="btn btn-info" id="import">
<input type="file" name="file">
</span>input type="submit" value="upload" id="submit">
这是我的api代码:
@api.route('/upload', methods=['POST','GET'])
def upload():
if request.method == 'POST':
file = request.files['file']
upload_path = os.path.join(APP_STATIC_TXT, secure_filename(file.filename))
file.save(upload_path)
return redirect(url_for('/'))
此运行结果:
信息:werkzeug:127.0.0.1 - - [14 / Dec / 2017 16:26:42]“POST /api/v1.0/upload HTTP / 1.1“400 - 信息:werkzeug:127.0.0.1 - - [14 / Dec / 2017 16:26:42]“POST / HTTP / 1.1”405 - 信息:werkzeug:*检测到的变化 '/home/python/Desktop/VCG/vcg/api_1_0/test01.py',正在重新加载
这是web html:
Method Not Allowed
请求的网址不允许使用该方法。
答案 0 :(得分:1)
使用form
在action
current view url
属性中。请将其更改为url_for('upload')