AttributeError: type object 'User' has no attribute 'query'

your User class is inheriting from UserMixin (from flask-login) which doesn't have a query attribute. can't fully explain the differences between our projects but here is my basic setup:

init.py:

from flask import Flask, render_template, session
from flask.ext.sqlalchemy import SQLAlchemy
import flask.ext.login as FL


# define the main app object
app = Flask(__name__)
app.config.from_object('config')
app.secret_key = 'super secret string'

login_manager = FL.LoginManager()
login_manager.init_app(app)
login_manager.login_view = "/"

# create the database object
db = SQLAlchemy(app)

then in models.py (make sure you import db) make User class inherit from db.Model:

from flasker import db
import datetime
from flask.ext.login import UserMixin

class User(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    email = db.Column(db.Unicode(128))
    name = db.Column(db.Unicode(128))
    password = db.Column(db.Unicode(1024))
    authenticated = db.Column(db.Boolean, default=False)
    posts = db.relationship('Post')
    #-----login requirements-----
    def is_active(self):
    #all users are active
        return True 

    def get_id(self):
        # returns the user e-mail. not sure who calls this
        return self.email

    def is_authenticated(self):
        return self.authenticated

    def is_anonymous(self):
        # False as we do not support annonymity
        return False

    #constructor
    def __init__(self, name=None, email=None, password=None):
        self.name = name
        self.email = email
        self.password = password
        self.authenticated = True

Add

Base.query = db_session.query_property()

under

Base = declarative_base()

in

database_setup.py

Ref: https://pythonhosted.org/Flask-Security/quickstart.html#id2


You can try to modify the way you create db Models like this:

class User(db.Model):
    # parms

Generally create Models in this way will be able to let User use query method. Hope it helps.