The request module for Python flask and the pits encountered in flask programming

Source: Internet
Author: User

First, to talk about the hole encountered:

1. Package references for Linux under:

1 """2 The path structure is as follows:3 ./project4 ./bin5 ./api6 """7 #to reference the contents of apilib.py in the API directory under main.py in the bin directory8 ImportSYS9Sys.path.append (".. /")Ten  fromApi.apilibImportFunc

2. When running large system, the execution directory of the script that you initiated under/root is also/root, so pay attention to the absolute path and relative path in programming.

3, under Linux How to adjust the bad Httpbasicauth

1 #The configuration of Httpbasicauth under Linux can only be defined in the app startup file. It hasn't been tuned so far:2 #can only be as follows:3Apiapp = Flask (__name__)4 #APIAPP.config.from_pyfile (".. /settings/flaskcconfig.py ", Silent=true)5 #in this way, the mother will make mistakes, do not know where the problem is!!! 6apiapp.config['Basic_auth_username'] ='******'7apiapp.config['Basic_auth_password'] ='******'8apiapp.config['DEBUG'] = True

Second, the request module in flask is important to obtain the relevant content of the requested message:

1. Request for data transfer:

1 request.forms.get ("xxxx")2 request.args.get (" xxxx ")

2. Request for Cookies

1 request.cookies

3, characters commonly used paragraph:

1Request.headers#Headers2Request.Files#Upload Files3Request.stream#Stream Data4Request.data#Data5Request.method#get \post \head\ ...6 Request.path7 Request.script_root8 Request.base_url9 Request.urlTenRequest.url_root

The request module for Python flask and the pits encountered in flask programming

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.