压缩Django REST中的响应有效内容? [英] Compressing the response payload in Django REST?
问题描述
我想知道:是否可以压缩Django REST中的响应有效内容?
I was wondering: would it be possible to compress the response payload in Django REST?
目前,响应有效内容是纯JSON数据。然而,有很多数据来回弹起来,所以我想知道压缩数据是否会有助于带宽问题。
At the moment, the response payloads are plain JSON data. However, there's quite a lot of data to bounce back and forth so I was wondering if compressing the data would help with the bandwidth issues.
推荐答案
HTTP响应压缩很可能不会被Django处理,而是使用gzip或deflate算法的HTTP服务器。
HTTP response compression will most likely not be handled by Django but by your HTTP server using the gzip or deflate algorithms.
您只需要确保您的HTTP服务器被配置为使用 Content-Type
头设置为 application / json
来压缩HTTP响应。
You just need to make sure your HTTP server is configured to compress HTTP Responses with Content-Type
header set to application/json
.
如何为nginx启用gzip压缩: https:// rtcamp。 com / tutorials / nginx / enable-gzip /
How to enable gzip compression for nginx: https://rtcamp.com/tutorials/nginx/enable-gzip/
这篇关于压缩Django REST中的响应有效内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!