I have such code:
from flask import Flask, render_template, redirect, request, url_for, session
app = Flask(__name__)
@app.route('/')
def index():
tmplt = session.get('template', 'No template')
return render_template('index.html', template=tmplt.decode('utf-8'))
@app.route('/template', methods=['POST'])
def upload_template():
session['template'] = request.files['template'].read()
return redirect(url_for('index'))
if __name__ == '__main__':
app.secret_key = '\x0cw1\xd4\xd5\x80%O?q \xcfQrrk\xa3H\xc0[J\xae<\xc3]\xe6\x10\xc0-\xf8S\x08P4[3]PrK\xa9\xf1'
app.run(debug=True)
I expect, that after successful execution of POST /template
, variable tmplt
will be equal to what was upload. However, it is empty. Debugging shows that session['template']
before redirection stores file content, as expected.
Anybody can suggest what's the problem here? Flask docs and googling didn't help :(