我正在使用Flask并尝试提供文件供用户下载。
我的代码看起来像这样:
@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
的例子,而且我并没有看到我正在做的事情有多大差异。所以任何帮助都将不胜感激。
答案 0 :(得分:11)
你必须从烧瓶中导入......它应该是......
SELECT *
FROM
(SELECT
t.[Statement_ID], t.[InvoiceID],
t.S_Type as Type, t.Description, t.Date,
t.Debit, t.Credit, b.Balance
FROM
Statement as t
CROSS apply
(SELECT Balance = SUM(Debit) - SUM(Credit)
FROM Statement as x
WHERE (x.date < t.date or x.date = t.date and x.[Statement_ID] <= t.[Statement_ID] )
AND x.CustID = t.CustID ) b
WHERE
t.CustID = '48'
AND date between '2015-01-01' AND '2016-01-01'
ORDER BY
t.date)
ORDER BY
InvoiceID, Statement_ID