Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

601
Visualizações
Django rest framework, set the api response Content-Encoding to gzip

Am working on django project, that act as a distribution server to other server when they request for some certain data through and api call, this data is in form of JSON and is very large. So i was thinking is there any way i can set my DRF APIView response to serves the outputted JSON response with gzip set for the Content-Encoding so as to reduce the size of the content, when consuming by the other servers.

Currently my application is running on gunicorn with nginx on the front as a proxy.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Django has a built-in gzip middleware.

If you're using django version <= 1.10 , in your settings.py:

MIDDLEWARE_CLASSES = [
    'django.middleware.gzip.GZipMiddleware',
    ...
]

If you're using django version > 1.10:

MIDDLEWARE = [
    'django.middleware.gzip.GZipMiddleware',
    ...
]

This middleware should be placed before any other middleware that need to read or write the response body so that compression happens afterward.

Why? Because for an incoming request django processes the request using middlewares from top to bottom as defined in your settings. For out going response middlewares are called bottom to top.

So declaring gzip middleware as the first middleware will enable the incoming request to be decompressed to be read by other middlewares ; and the outgoing response will be compressed just before leaving, so that it does not interfere with the operations of other middlewares.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda