- Author:
- SmileyChris
- Posted:
- July 24, 2008
- Language:
- Python
- Version:
- .96
- Score:
- 1 (after 1 ratings)
Rather than using the full GZipMiddleware, you may want to just compress some views. This decorator lets you do that.
@gzip_compress
def your_view(request, ...):
....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.middleware.gzip import GZipMiddleware
gzip_middleware = GZipMiddleware()
def gzip_compress(func):
"""
Gzip compress an individual view rather than requiring the whole site to
use the Gzip middleware.
"""
@wraps(func)
def dec(request, *args, **kwargs):
response = func(request, *args, **kwargs)
return gzip_middleware.process_response(request, response)
return dec
|
More like this
- Stuff by NixonDash 1 month ago
- Add custom fields to the built-in Group model by jmoppel 3 months, 1 week ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 3 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 7 months, 1 week ago
- Browser-native date input field by kytta 8 months, 3 weeks ago
Comments
Note that you can also use django.utils.decorator_from_middleware to achieve the same thing.
#
sorry, that should have been django.utils.decorators
#
Please login first before commenting.