Web development based on hi-nginx (python)-form processing and File Upload,

Source: Internet
Author: User

Web development based on hi-nginx (python)-form processing and File Upload,

Hi-nginx will automatically process the form. Therefore, in the hi. py framework, you must directly use the data.

Form data is generally submitted using the GET and POST methods. Hi-nginx parses the data and stores it in the form member variable. For python, you must use the has_form and get_form methods to retrieve the desired data.

For example, the route is as follows:

@app.route('^/form/?$',['GET','POST'])def form(req,res,param):    name='None'    if req.has_form('name'):        name=req.get_form('name')    res.content('{}={}'.format('name',name))    res.status(200)

The preceding route indicates that you can use get or post to submit data named name to/form. You can use curl to test:

Curl-I http: // localhost: 8080/form? Name = 123

Or

Curl-I-d 'name = 123 'http: // localhost: 8080/form

The method for processing forms using hi. py is as simple as this.

The preceding routes can also directly process file uploads. You only need to understand the name as the temporary address of the file to be uploaded:

Echo 'test upload file'> name. file

Curl-I-f'name = @ name. file 'HTTP: // localhost: 8080/form

 

This indicates that when we upload the file name. file to/form, the file will be temporarily saved in the temp directory under the hi-nginx installation directory. The file name is temp/94ffcfe29b03c0c71_a2fdd842d54ca. file. Therefore, we only need to move the file to the desired address.

Because the file size exists, the server also limits the file size, so it is best to use client_max_body_size of nginx, such

client_max_body_size 100k;

Command to limit the size of file upload.

 

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.