这是我动态创建文件的函数(当用户单击正确的链接时)
@app.route('/survey/<survey_id>/report')
def survey_downloadreport(survey_id):
survey, bsonobj = survey_get(survey_id) #get object
resps = response_get_multi(survey_id) #get responses to the object
fields = ["_id", "sid", "date", "user_ip"] #meta-fields
fields.extend(survey.formfields) #survey-specific fields
randname = "".join(random.sample(string.letters + string.digits, 15)) + ".csv" #some random file name
with open("static//" + randname, "wb") as csvf:
wr = csv.DictWriter(csvf, fields, encoding = 'cp949')
wr.writerow(dict(zip(fields, fields))) #dummy, to explain what each column means
for resp in resps :
wr.writerow(resp)
return send_from_directory("static", randname, as_attachment = True)
我想在下载完成后删除文件。我该怎么做?