在python3中使用flask上传多个文本文件

时间:2019-09-09 14:35:32

标签: python flask

我正在制作一个webtool,我要在其中上传一些文本文件,为此,我按如下方式使用flask :(我有2个脚本:1- {flask.py和第二个脚本是:upload.html

flask.py

from flask import Flask, render_template, request
from werkzeug import secure_filename
app = Flask(__name__)

@app.route('/upload')
def upload_file():
   return render_template('upload.html')

@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
   if request.method == 'POST':
      f = request.files['file']
      f.save(secure_filename(f.filename))
      return 'file uploaded successfully'

if __name__ == '__main__':
   app.run(debug = True)

,模板文件夹中的第二个脚本是:

upload.html

<html>
   <body>
      <form action = "http://localhost:5000/uploader" method = "POST" 
         enctype = "multipart/form-data">
         <input type = "file" name = "file" />
         <input type = "submit"/>
      </form>
   </body>
</html>

当我运行它时,会出现此错误:

AssertionError: View function mapping is overwriting an existing endpoint function: upload_file

您知道如何解决吗?

0 个答案:

没有答案