Web development based on hi-nginx (python) -- start, hi-nginxpython

Source: Internet
Author: User

Web development based on hi-nginx (python) -- start, hi-nginxpython

Hi-nginx not only makes python web applications run fast, but also makes related development simple and agile.

For the installation of hi-nginx, see: https://www.cnblogs.com/hi-nginx/p/8622561.html

It is often said thatFlaskThe framework is fast and good. However, it is still too slow to compare hi-nginx. For exampleFlaskThe minimum application of is as follows:

1 from flask import Flask2 app = Flask(__name__)3 4 @app.route('/')5 def hello_world():6     return 'Hello World!'7 8 if __name__ == '__main__':9     app.run()

However, the minimum python application of hi-nginx is simpler:

1 if hi_req.uri()=='/test.py':2     hi_res.content('hello,world')3     hi_res.status(200)

Of course, you can also make the minimum application write more complex, such:

 1 def hello_world(): 2     hi_res.content('hello,world') 3     hi_res.status(200) 4  5 def run(): 6     if hi_req.uri()=='/': 7         hello_world() 8  9 if __name__ == '__main__':10     run()

How can I access the application after it is written? It's easy to write in the hi-nginx configuration file as follows:

server {        listen 8080;        server_name localhost;        location / {                hi_need_cache off;                hi_python_script python/index.py;        }}

Reload or restart nginx, and then visit http: // localhost: 8080/To see hello, world greetings.

Now we use siege to test the performance of this minimum application:

Siege-c 1000-r 100-B http: // 127.0.0.1: 8080/


Are you satisfied!

 

Related Article

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.