Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...