flask中给cookie绑定、删除ticket的操作和django中完全一样,此处不做详细说明,可参考文章:DJango用自己的方法实现登陆注册
1.给 cookie 绑定 ticket
@blue.route('/getresponse/')
def get_response():
response = make_response('<h2>你是大傻逼</h2>', 200)
ticket = 'ticket_'
s = '1234567890qwertyuiopasdfghjklzxcvbnm'
for i in range(20):
ticket += random.choice(s)
response.set_cookie('ticket', ticket, expires=time.time() + 60*60*24)
return response
2.删除cookie的ticket
@blue.route('/deletecookie/')
def delete_cookie():
response = make_response('<h2>你是大傻逼</h2>', 200)
response.delete_cookie('ticket')
return response
网友评论