#从flask——restful中导入Api
from flask_restful import Api
#创建蓝图
api_bp = Blueprint('api', __name__)
#实例化Api
api = Api(api_bp)
#导入视图函数名字
from .user import UserLogin, UserInfo
api.add_resource(UserLoginView, '/user/login', endpoint='login')
api.add_resource(视图函数名字, '请求路径')
#视图函数
class UserLoginView(Resource):
@marshal_with(result_fields)
def post(self):
parse = reqparse.RequestParser()
parse.add_argument('username', type=str)
parse.add_argument('password', type=str)
args = parse.parse_args()
if args['username'] is None:
raise usernullError()
if args['password'] is None:
raise passwordnullError()
token = login(username=args['username'], password=args['password'])
if token is None:
raise userOrpasswordError()
return Result.success(token.decode())