Python Flask会话丢失键值
我有一个烧瓶会议的问题。重定向后会丢失值,下面是我使用的代码:Python Flask会话丢失键值,python,python-2.7,session,flask,youtube-data-api,Python,Python 2.7,Session,Flask,Youtube Data Api,我有一个烧瓶会议的问题。重定向后会丢失值,下面是我使用的代码: @app.route('/') def index(): session['permanent'] = True return flask.render_template('index.html') ##Here is template with form that passes value via GET to /station @app.route('/station', methods=['GET']) de
@app.route('/')
def index():
session['permanent'] = True
return flask.render_template('index.html') ##Here is template with form that passes value via GET to /station
@app.route('/station', methods=['GET'])
def station():
if 'st' not in session:
p = flask.request.args.get('Station', '')
session['st'] = p
print session['st']
if 'credentials' not in session:
return flask.redirect(flask.url_for('oauth2callback'))
credentials = client.OAuth2Credentials.from_json(session['credentials'])
if credentials.access_token_expired:
return flask.redirect(flask.url_for('oauth2callback'))
else:
##DO SOME STUFF WITH st and credentials##
return "Done!"
@app.route('/oauth2callback')
def oauth2callback():
flow = client.flow_from_clientsecrets('client_secret.json',scope='https://www.googleapis.com/auth/youtube',redirect_uri=flask.url_for('oauth2callback', _external=True))
if 'code' not in flask.request.args:
auth_uri = flow.step1_get_authorize_url()
return flask.redirect(auth_uri)
else:
auth_code = flask.request.args.get('code')
credentials = flow.step2_exchange(auth_code)
session['credentials'] = credentials.to_json()
return flask.redirect(flask.url_for('station'))
结果是:Firts浏览器呈现index.html。很好,用户单击某个内容并将GET参数传递给station()。它通过:
if 'st' not in session
会话密钥设置正确。我在报纸上看到了。然后将用户重定向到/oauth2callback。通过youtube api和脚本将用户从/oauth2callback带回/station时,有整个身份验证过程
return flask.redirect(flask.url_for('station'))
由于某种原因,代码进入
如果“st”不在会话中
再一次。好像再也没有会议了。在结果中,我没有表单中的值。。。
我不知道该怎么办。(使用Flask 0.10并在Heroku上托管内容)嘿,你找到解决方案了吗。我也有同样的问题,但在Google App Engine上,我在考虑系统缩放和移动用户的方式,它不发送会话数据,因为从技术上讲,这是一个新的会话。因此,我的用户被迫反复登录。