Skip to content

Instantly share code, notes, and snippets.

@john100ster
Last active May 25, 2021 02:54
Show Gist options
  • Save john100ster/80dad74e5d2af5638e990d38fc75144b to your computer and use it in GitHub Desktop.
Save john100ster/80dad74e5d2af5638e990d38fc75144b to your computer and use it in GitHub Desktop.
[python flask token 校验 装饰器]#flask
from flask import request
from app.libs.token_auth import verify_auth_token
def login_required(fun):
def wrapper(*args, **kwargs):
headers = request.headers
auth = headers.get("Authorization")
verify_result = verify_auth_token(auth.split(" ")[1])
return fun(*args, **kwargs)
return wrapper
# 使用
from flask_restful import Resource
from app.models.server import Server
from app.libs.error_code import Success
from app.libs.login_required import login_required
class HandleGetIp(Resource):
@login_required
def get(self):
servers = Server.query.order_by("id").all()
return {"code": "hello", "data": [Server.serialize(record) for record in servers]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment