A simple replacement for Django's default GZipMiddleware which breaks when trying to serve files or pass any kind of iterators to the HttpResponse object.
Simply replace GZipMiddleware with the provided middleware and set response.dontgzip = True when returning the response, and it will then be ignored by the middleware.
1 2 3 4 5 6 7
from django.middleware.gzip import GZipMiddleware class FixedGZipMiddleware(GZipMiddleware): def process_response(self, request, response): if hasattr(response, 'dontgzip'): return response return GZipMiddleware.process_response(self, request, response)
More like this
- A wrapper around cache_page making it optional by rixx 1 day, 18 hours ago
- Treat empty value on DateRangeFilter as a filter for non filled dates by kmmbvnr 1 month, 1 week ago
- Django Settings Assignment Expressions aka Walrus Operator example by webology 2 months, 1 week ago
- codigo alto nivel by MrRocklion 4 months, 1 week ago
- Load template from specific app by Krzysiek555 4 months, 4 weeks ago