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
- Log in a user without requiring credentials by SmileyChris 3 years, 11 months ago
- Smart {% if %} template tag by SmileyChris 4 years, 2 months ago
- Cookieless Session Decorator by achimnol 3 years, 9 months ago
- DRYer instantiation of Forms by SmileyChris 4 years, 1 month ago
- Nice form errors by SmileyChris 3 years, 7 months 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
#