Flask uses session to save logon status and intercept codes of Unlogged requests. flasksession
This article mainly studies flask's usage of session to save login status and intercept Unlogged requests. The details are as follows.
Front-end request form:
<Form action = "/user/add" method = "get"> <input type = "text" name = "username" value = "111"> <input type = "submit "value =" Submit "> </form>
When the front-end submits the request, the backend receives parameters and saves the login data in the session:
@user.route('/add',methods=['GET']) def add(): username=request.values.get('username'); session['username']=username return session['username']
Used to obtain form data
request.values.get('username');
Check box parameter acquisition:
s_option = request.values.getlist("s_option") for s in s_option: pass
Use @ before_request to intercept the request url
@ User. before_request def before_user (): if 'username' in session: return 'logged on 'pass else: return' not logged on'
If you have logged on, You can intercept it. If you have not logged on, a prompt is returned or you are redirected to the logon page.
Summary
The above is all about flask's use of session to save login status and intercept Unlogged request code. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!