Flask uses session to save logon status and intercept codes of Unlogged requests. flasksession

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.