[Flask] Flask problem sets

The difference 1.redirect and render_template?

redirect: Redirect, will change the url

render_template: template rendering, use templates to render the current page, not change url

 

2. With regard to 'g' objects stepped pit

【description】

Blog items, objects in settings g login request, made objects in the g register request, obtain None

@bp.route('/login',methods=('GET','POST'))
def login():
    #...
    g.myname = 'john'

@bp.route('/register',methods=('GET','POST'))
def register():
    #...
    name = g.get('myname')
    print(name) # None

【analysis】

文档中说道:To share data that is valid for one request only from one function to another ...

Note that the first request, once!

 

Guess you like

Origin www.cnblogs.com/remly/p/11755489.html