class BaseHandler(tornado.web.RequestHandler): def allowMyOrigin(self): allow_list = [ ‘http://127.0.0.1:7100‘, ] Origin = self.request.headers[‘Origin‘] # 域名 re_ret = re.match(r".{1,}\.(haha.com|xixi.com)", Origin) # 内网和本地 re_ret2 = re.match(r"^(192.168.1.*|127.0.0.1.*|192.168.2.*)", Origin) if re_ret or re_ret2 or Origin in allow_list: self.set_header("Access-Control-Allow-Origin", Origin) # 这个地方可以写域名 self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header(‘Access-Control-Allow-Methods‘, ‘POST, GET, OPTIONS‘) class AuthImageHandler(BaseHandler): def set_default_headers(self): self.allowMyOrigin() def get(self, *args, **kwargs): pass
原文地址:https://www.cnblogs.com/zhangkui/p/11416575.html
时间: 2024-10-15 11:48:06