简体   繁体   中英

Server Error in Django Web app

I'm following this tutorial to fix a cache problem, since I'm using google analytics. After trying the code, I'm getting

A server error occurred.  Please contact the administrator.

middleware.py

from django.middleware.cache import UpdateCacheMiddleware

import re

class SmartUpdateCacheMiddleware(UpdateCacheMiddleware):
      STRIP_RE=re.compile(r'\b(_[^=]+=.+?(?:; |$))' )

      def process_request(self,request):
          cookie=self.STRIP_RE.sub(",request.META.get('HTTP_COOKIE',")) #error
          request.META['HTTP_COOKIE']=cookie

In my cmd terminal I'm getting this error

  File "C:\Python27\Scripts\env\Scripts\meek\meek\middleware.py", line 9
  cookie=self.STRIP_RE.sub(",request.META.get('HTTP_COOKIE',"))

I tried fixing it but it's not working.

You seem to have cut-and-pasted with a typo. It should be:

cookie = self.STRIP_RE.sub('', request.META.get('HTTP_COOKIE', ''))

You collapsed the double single quotes into a single double quote mark:

cookie=self.STRIP_RE.sub(",request.META.get('HTTP_COOKIE',"))
                         ^                                ^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM