1
後,我有這樣的代碼:瓶會話是空的重定向
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)
我想到,這的POST /template
成功執行後,變量tmplt
將等於什麼上傳。但是,它是空的。調試顯示重定向前的session['template']
存儲文件內容,如預期的那樣。
有人可以建議這裏有什麼問題嗎?瓶文檔和谷歌搜索沒有幫助:(
這麼簡單...謝謝! –
請問如何解決這個問題? – hubert
@hubert如果你有上述問題(會話數據太大而無法存儲在cookie中),那麼您需要更改代碼以減小數據量 - 不要將大的東西存儲到cookie中,或使用瀏覽器本地存儲來保存用戶數據而不是cookie(或兩者都像在cookie中擁有用戶身份信息一樣,因此您可以識別服務器上的用戶並將用戶數據緩存到本地存儲中)。 –