简体   繁体   中英

Tornado set_secure_cookie

When I set a value in a set_secure_cookie function in Python Tornado, I can get the value whit a get_secure_cookie function when I make a redirec , but when I use a render action it doesn't appear.

form = UserAddForm(self.request.arguments)
if form.validate():
    record = User(**form.data)
    self.db.add(record)
    self.db.commit()
    self.set_secure_cookie("flash", "success")
    self.redirect("/user") # Show the flash message with self.get_secure_cookie("flash")
else:
    self.set_secure_cookie("flash", "error")
    self.render("user/add.html", form=form) # Don't show the flash message with self.get_secure_cookie("flash")

函数“set_cookie”将在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