您具有
send_from_directory
函数,该函数可以执行您想要的操作,我要做的是使用媒体文件所在的路径声明一个名为 MEDIA_FOLDER
的常量,然后,您唯一需要做的就是这样调用该函数:
from config import MEDIA_FOLDER@app.route('/uploads/<path:filename>')def download_file(filename): return send_from_directory(MEDIA_FOLDER, filename, as_attachment=True)然后,要调用它,只需执行以下操作:
{{ url_for('download_file', filename='dogs.jpg') }}您可以在此处了解更多信息。



