【发布时间】:2021-07-23 22:33:28
【问题描述】:
我有一个接受 get 和 post 请求的烧瓶视图,我使用 Pydantic 使用 flask-pydantic 进行请求正文验证。它适用于发布请求,但在获取请求时,它会返回带有此消息的 415 错误 - {"detail":"请求中不支持的媒体类型''。需要'application/json'。"}
@bp.route('/login', methods=('GET', 'POST',))
@validate()
def login(body: UserLoginSchema):
if request.method == 'POST':
existing_user = UserListSchema.from_orm(
db_session.query(UserModel.id, UserModel.email, UserModel.first_name, UserModel.last_name,
UserModel.is_admin, UserModel.is_verified, UserModel.password)
.filter_by(email=body.email, is_active=True).first()
)
if existing_user:
if check_password_hash(existing_user.password, body.password):
session.clear()
session['user'] = str(existing_user.json())
return redirect(url_for('index'))
flash('Invalid username or password')
return render_template('auth/login.html')
我尝试将函数中的 query 参数设置为空字符串或 None,但没有帮助。
【问题讨论】: