路由地址:api/session post请求
class Session(Resource):
@marshal_with(t)
def post(self):
print('1111111111')
login_args = login_parser.parse_args()
user = {}
user['a'] = login_args.username
print(user)
print(login_args.username)
result = login(login_args.username, login_args.password)
print(result)
return result
#login()方法如下
def login(username,password):
user = User.query.filter_by(username=username).first()
if user is None:
return {'msg':'不存在'}
return {'id':1,
'success':2,
'token':3}
#login_parser如下
login_parser = reqparse.RequestParser()
login_parser.add_argument(
'username', type='str', location=['json'],required=True, help='用户名参数有误'
)
login_parser.add_argument(
'password', type='str', location=['json'], required=True, help='密码参数有误'
)
postman请求 在请求头里设置了application/json
请求body
{
"username":"test",
"password":"111"
}
现在请求返回400
{
"message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"
}