import jwt def generate_jwt(username): # https://www.jianshu.com/p/03ad32c1586c headers = { "alg": "HS256", "typ": "JWT" } salt = "acvv" payload = { "name": username } token = jwt.encode(payload=payload, key=salt, algorithm='HS256', headers=headers).decode('utf-8') return token def check_jwt(cookie_jwt): salt = "acvv" info = jwt.decode(cookie_jwt, salt, True, algorithm='HS256') return info['name']