Without Nginx, the flask data can be automatically gzip.

Source: Internet
Author: User

Without Nginx, the flask data can be automatically gzip.

I used Flask to do a little thing myself, but the data in it is huge. Every time I get data from the server, I have to download more than 5 MB of data. I don't want to bother with the O & M shoes to change the configuration in Nginx, so I found the flask-compress.

 

How to use it? Easy

First download

1
pip install flask-compress

Then, when the app is initialized

1
2
3
4
5
from flask import Flask
from flask.ext.compress import Compress

app = Flask(__name__)
Compress(app)

Of course, it may not be possible only during initialization.

1
2
3
4
5
6
7
8
9
from flask import Flask
from flask.ext.compress import Compress

compress = Compress()

def start_app():
app = Flask(__name__)
compress.init_app(app)
return app

In practice, the results are infinitely good and no bugs have been found.
Of course, if the business volume is large, you should be honest with nginx.

This article permanently updates the link address:

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.