【发布时间】:2017-12-14 08:53:53
【问题描述】:
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/上传 HTTP/1.1" 400 - INFO:werkzeug:127.0.0.1 - - [14/Dec/2017 16:26:42] "POST / HTTP/1.1" 405 - INFO:werkzeug: * 检测到变化 '/home/python/Desktop/VCG/vcg/api_1_0/test01.py', 重新加载
这是网页 html:
Method Not Allowed
请求的 URL 不允许该方法。
【问题讨论】:
-
请在此处包含代码并正确格式化您的问题