我在我的应用程序中使用Flask会话。在我的处理程序之一中,我设置了会话值,在其他处理程序中没有设置会话。但是,我发现在每个响应中都存在一个HTTP头:Set-Cookie
。为什么会这样?
app = Flask(__name__)
app.secret_key = r"A0Zr98j/3yX R~XHH!jmN'LWX/,?RT"
@app.route('/auth/login', methods=['POST'])
@crossdomain(origin='*')
def authlogin():
user = User(username=username, registered_at=sqlnow())
user.accounts = [Account(provider='weibo', access_token=access_token, uid=uid)]
account = user.accounts[0]
session['user_id'] = account.user_id
return jsonify({
'status': 'success',
'data': {
'user_id': account.user_id,
'uid': account.uid
}
})
@app.route('/api/movies/<movie_type>')
def moviescoming(movie_type):
if movie_type == 'coming':
return getmovies(MOVIE_TYPE_PLAYING, offset, limit)
else:
return getmovies(MOVIE_TYPE_COMING, offset, limit)
app.run(host='0.0.0.0', debug=True)
这里展示代码: https://github.com/aisensiy/dianying/blob/master/index.py