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

0 0 python flask
TimoTolkki
TimoTolkki

声望值:135 0人

2019-03-09 08:59:14 提问

关注 0关注

收藏 0收藏, 344浏览

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:

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

请先 登录 后评论

1个回答

  • -II、执念213声望 2018-09-25 09:26

    把最后一行 return redirect(url_for('/upload')) 改成 return render_template('你的html')
    请先 登录 后评论

注册新账号

悬赏追问
10
  • 10
  • 20
  • 50
  • 100
  • 200
  • 输入数值
发布追问