Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

python - AttributeError: type object 'Auth' has no attribute 'query'

So I've been using this method for a few projects now but for some reason I'm getting an error.

Code involved:

class Auth(db.Column):
    __tablename__ = 'ezauth'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    username = db.Column(db.String, nullable=False)
    email = db.Column(db.String, nullable=False)
    password = db.Column(db.String, nullable=False)
    confirmed = db.Column(db.Boolean, nullable=False, default=False)

    def __repr__(self):
        return f"Auth(username='{self.username}', email='{self.email}', password='{self.password}'"

and

@app.route('/api/login', methods=['POST'])
def apilogin():
    if request.method == 'POST':
        email = request.form.get('email')
        password = request.form.get('password')
        if email != None and password != None:
            value1 = Auth.query.filter_by(email=email).first()
            if value1 != None:
                db_pass = value1.password
                oid = value1.id
                if sha256_crypt.verify(str(password), db_pass):
                    token = create_token()
                    tokendb = Token(token=token, oid=oid)
                    return Response('{"success": true, "message": "Logged in", "token": "' + str(token) + '"}', status=200, mimetype='application/json')
                else:
                    return Response('{"success": false, "message": "Incorrect password"}', status=400, mimetype='application/json')
            else:
                return Response('{"success": false, "message": "Email not registered"}', status=400, mimetype='application/json')
        else:
            return Response('{"success": false, "message": "Wrong form parameters"}', status=400, mimetype='application/json')

But, the Auth.query.all() (or any other variation on Auth.query) doesn't work for some reason, it returns the AttributeError: type object 'Auth' has no attribute 'query' error. It has worked in previous projects, just not this one.

question from:https://stackoverflow.com/questions/65883383/attributeerror-type-object-auth-has-no-attribute-query

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...