send a file on request

stable
neingeist 6 years ago
parent c56c1226d3
commit e340e967a6

@ -1,4 +1,4 @@
from flask import render_template, flash, redirect, url_for, request
from flask import render_template, flash, redirect, url_for, request, send_from_directory
from app import app
from app.forms import DownloadForm
from datetime import datetime, timedelta
@ -12,10 +12,12 @@ def index():
def download():
form = DownloadForm()
if form.validate_on_submit():
flash('Download requested: {}, length={}'.format(
form.date.data, form.length.data))
return redirect(url_for('index'))
return render_template('download_thanks.html', title='Download', form=form)
elif request.method == 'GET':
form.date.data = datetime.now() - timedelta(hours = 1)
form.length.data = 60
return render_template('download.html', title='Download', form=form)
@app.route('/download_file/<path:filename>')
def download_file(filename):
return send_from_directory(app.config['DATA_DIR'], filename, as_attachment=True)

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block head %}
{{ super() }}
<meta http-equiv="refresh" content="0;URL='download_file/test.mp3'" />
{% endblock %}
{% block app_content %}
<h1>Thanks!</h1>
{% endblock %}
Loading…
Cancel
Save