我已经完成了,但是现在我想在另一个路径中返回这个图像(如果我想要下载的话,可以看到它),然后flask返回给我这个错误:“name 'send_file‘is not defined”。我哪里做错了?有没有更好的方法呢?
@app.route('/upload', methods=['GET','POST'])
@login_required
def upload():
if request.method == "POST":
if not allowed_image_size(request.cookies.get("filesize")):
return redirect(request.url)
file = request.files['image']
comentaries = request.form['comentaries']
if not allowed_image(file.filename):
return('No valid extencion')
#return redirect(request.url
else:
filename = secure_filename(file.filename)
newFile = FileContent(client_name=current_user.username, comments=comentaries, data=file.read())
db.session.add(newFile)
db.session.commit()
return 'Saved ' + file.filename + ' to the database'
return render_template('upload.html')
@app.route('/download')
def download():
file_data = FileContent.query.all()
return send_file(BytesIO(file_data.data), attachment_filname='egreso.jpg', as_attachment=True)
发布于 2021-01-01 19:06:21
你面对的错误是"name 'send_file' is not defined"
说的。
这说明您应该从flask
导入send_file
函数,如下所示:
from flask import send_file
https://stackoverflow.com/questions/65509537
复制相似问题