0
我正在使用Flask并尝试提供用户下载的文件。NameError:未定义全局名称'send_from_directory'
我的代码看起来是这样的:
@app.route('/downloads/<string:yt_id>')
def download_file(yt_id):
def hooks(data):
if data['status'] == 'finished':
filename = data['filename']
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'progress_hooks': [hooks],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v='+yt_id])
return send_from_directory(".",
filename,
as_attachment=True)
我想上面的代码的唯一相关的部分是这样的:
return send_from_directory(".",
filename,
as_attachment=True)
这是我得到的错误信息:
NameError: global name 'send_from_directory' is not defined
我看了几个人如何使用的例子send_from_directory
a nd我没有看到与我正在做的事情有很大的区别。所以任何帮助将不胜感激。
嗯...有你'导入send_from_directory'? –