caching - Can Django-cms pages incorporate the vary_on_headers decorator? -


i'm building site using django-cms , we're using mobileesp detect user-agent , serve different templates , content depending on device being used view site.

the issue django-cms's built in page caching, users seeing wrong content depending on version of page cached. example, if desktop version of site viewed first , cached, users visiting site on smartphone still see desktop version instead of mobile version.

with traditional django views resolved using @vary_on_headers('user-agent') ensure different versions of site correctly cached.

is possible apply logic django-cms views how?

i managed figure out way work around issue using patch_vary_headers() functionality in custom middleware class. had platform detection middleware added mobile/desktop setting request object. added process_response function middleware , patched there. far appears working correctly.

class platformdetectionmiddleware (object):      def process_request(self, request):         user_agent = request.meta.get("http_user_agent")         http_accept = request.meta.get("http_accept")          agent = mdetect.uagentinfo(useragent=user_agent, httpaccept=http_accept)         request.is_tablet = agent.detecttiertablet()         request.is_mobile = agent.detecttieriphone()      def process_response(self, request, response):         patch_vary_headers(response, ['user-agent'])         return response 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -