") class User(MethodView): @blp.r" /> ") class User(MethodView): @blp.r" /> ") class User(MethodView): @blp.r"/>

Flask api rest error in filter using string into request

77 Views Asked by At

i implemented in my flask api rest app, this code to get the use from id into database:

@blp.route("/v0/user/<int:id>")
class User(MethodView):
    @blp.response(200, UserSchema)
    def get(self, id):
        user = UserModel.query.get_or_404(id)
        return user

now i want to implement the same logic to get only user passing uuid_user that is a value of model user and is in my database, using this code:

@blp.route("/v0/user_uuid/<string:uuid_user>")
class UserUuid(MethodView):
    @blp.response(200, UserSchema)
    def get(self,uuid_user):
        user = UserModel.query.filter(uuid_user).all()
        return user

but i receive this error when i call the endpoint of this api:

File "/app/resources/user.py", line 150, in get
    user = UserModel.query.filter(uuid_user).all()
  File "<string>", line 2, in filter
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/base.py", line 248, in _generative"

Any help how to fix it? Where is the error? Thanks

1

There are 1 best solutions below

0
dev_ On

thanks for your replay. I have fixed the issue in this way:

@blp.route("/v0/user_uuid/<string:uuid_user>")
class UserUuid(MethodView):
@blp.response(200, UserSchema)
def get(self,uuid_user):
    user = UserModel.query.filter_by(uuid_user = uuid_user).first_or_404()
    return user