我正在尝试制作一个简单的 Web 应用程序,可以在其中上传文件并将文件提供给 python 脚本。Flask 似乎适合这样的目的。然后,用户可以从脚本下载文件输出。请让我知道如何在 python 脚本中解析文件并获取输出。到目前为止,我设法执行以下上传文件的操作:
from flask import Flask
from flask import request
app = Flask(__name__)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form
'''
app.run()