send a file on request
This commit is contained in:
parent
c56c1226d3
commit
e340e967a6
2 changed files with 16 additions and 4 deletions
|
@ -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 import app
|
||||||
from app.forms import DownloadForm
|
from app.forms import DownloadForm
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
@ -12,10 +12,12 @@ def index():
|
||||||
def download():
|
def download():
|
||||||
form = DownloadForm()
|
form = DownloadForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
flash('Download requested: {}, length={}'.format(
|
return render_template('download_thanks.html', title='Download', form=form)
|
||||||
form.date.data, form.length.data))
|
|
||||||
return redirect(url_for('index'))
|
|
||||||
elif request.method == 'GET':
|
elif request.method == 'GET':
|
||||||
form.date.data = datetime.now() - timedelta(hours = 1)
|
form.date.data = datetime.now() - timedelta(hours = 1)
|
||||||
form.length.data = 60
|
form.length.data = 60
|
||||||
return render_template('download.html', title='Download', form=form)
|
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)
|
||||||
|
|
10
app/templates/download_thanks.html
Normal file
10
app/templates/download_thanks.html
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue