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.