我有同样的问题,我想出了另一个最小的解决方案。
首先,创建自己的继承原始的中间件UpdateCacheMiddleware
:
#! /usr/bin/env python
from django.conf import settings
from django.middleware.cache import UpdateCacheMiddleware
class MyUpdateCacheMiddleware(UpdateCacheMiddleware):
def process_response(self, request, response):
full_path = request.get_full_path()
# loop on our CACHE_MIDDLEWARE_IGNORE to ignore certain urls
for ignore in settings.CACHE_MIDDLEWARE_IGNORE:
if ignore.match(full_path):
return response
# ignore patterns missed, pass it to the original middleware
return super(MyUpdateCacheMiddleware, self).process_response(
request, response
)
然后在您的设置中创建一个忽略正则表达式列表,类似于:
CACHE_MIDDLEWARE_IGNORE = (
re.compile(r'^/admin/'),
)
现在你需要做的就是用UpdateCacheMiddleware
你创建的替换你的:
MIDDLEWARE_CLASSES = (
'myapp.lib.middlewares.MyUpdateCacheMiddleware',
# ...
'django.middleware.cache.FetchFromCacheMiddleware',
)
干杯。