Flask upload , The method is not allowed for the requested URL,

新手上路,请多包涵
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'

This is my a part of 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">

This is my api code and run result:

@api.route('/upload', methods=['POST','GET'])
def upload():
if request.method == 'POST':
    print '-'*100
    print request.files
    f = request.files['file']
    upload_path = os.path.join(APP_STATIC_TXT, secure_filename(f.filename))
    file.save(upload_path)
    return redirect(url_for('/upload'))

clipboard.png
This is web run result:

clipboard.png

阅读 6.7k
1 个回答

把最后一行

return redirect(url_for('/upload'))

改成

return render_template('你的html')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题