try:
    user = active.where(User.username == request.form['username']).get()
except User.DoesNotExist:
    return make_response(jsonify({'error': 'Bad request'}), 400)
Как изменить поведение UserDoesNotExist SELECT в Flask-peewee — python и mysql