tornado中关闭autoescape

本文讨论了在Tornado框架2.1版本中,使用xsrf_form_html函数时遇到的自动转义问题,通过调整settings配置中的autoescape属性为None来解决浏览器显示问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2.1版本中的tornado,使用了自动的escape功能,这个在使用xsrf_form_html函数的时候,会将这些字符转义出来,导致浏览器出现本应该隐藏内容的显示问题。

在tornado.web中,有关于autoescape方法的获取,发现在settings中修改即可。
于是在settings中添加 "autoescape":None

问题得以解决。

settings 配置
settings = {
"debug" : True, # will auto reload
"cookie_secret": "jNU893FLQp3vauUciqEQZbTtBSApVSp4IvNZj19V/Vo=",
"login_url" : "/login",
"xsrf_cookies" : True,
"static_url_prefix" : "/static/",
"template_path" : os.path.join( workpath, "template"),
"static_path" : os.path.join( workpath, "static"),
"autoescape" : None
}



 
application = tornado.web.Application([
(r"/",MainHandler),
(r"/login",loginHandler),
],**settings) #这儿传入
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值