按我的理解嘛
g是基于每个请求的,也就是说,每个请求中的g对象是不一样的,每个g对象的生命周期就是当前请求。
session就是传统意义上的session了。只要它还未失效(用户未关闭浏览器、没有超过设定的失效时间),那么不同的请求会共用同样的session。
可以向模板(template)传递多个参数或者把全部的本地参数传递给template:
1. 传递多个参数给template,直接将参数放在render_template()函数里面,参数间用逗号隔开:
@app.route('/')
def index():
content = '.....'
user='Micheal'
return render_template('index.html',var1=content, var2=user)
template中可以直接使用{{var1}}和{{var2}}直接操作变量。
2. 传递全部的本地变量给template,使用**locals():
@app.route('/')
def index():
content = '.....'
user='Micheal'
return render_template('index.html',**locals())
template中可以直接使用{{content}}和{{user}}直接操作变量。