跳转前设置Cookie

代码示例

from lessweb import Application, Response, Request, HttpStatus

def jump(resp: Response, target):
    resp.set_cookie('token', 'TOKEN_TEXT', expires=10**9, path='/')
    resp.send_redirect(location=target)
    resp.set_status(HttpStatus.SeeOther)
    return ''

def home(req: Request):
    token = req.get_cookie('token')
    return 'hello, %s!' % token

app = Application()
app.add_get_mapping('/jump', jump)
app.add_get_mapping('/', home)

if __name__ == '__main__':
    app.run()

测试

在浏览器地址栏输入http://localhost:8080/jump?target=/,浏览器会自动跳转到http://localhost:8080/并且页面显示hello, TOKEN_TEXT!