postgresql - Sqlalchemy does not work with pagination -
i totally new flask , sqlalchemy. try make 1 web site better understanding of flask. there plenty of tutorials , use sqlite. purpose use postgres. , need 1 page can use pagination. time getting error
attributeerror: 'query' object has no attribute 'paginate'
my database
uri = os.environ.get('database_url', 'postgres://login:password@127.0.0.1/db_name') engine = create_engine(uri, convert_unicode=true) db_session = scoped_session(sessionmaker(autocommit=false, autoflush=false, bind=engine)) base = declarative_base() base.query = db_session.query_property()
simple model
class user(base): __tablename__ = 'user' id = column(integer, primary_key=true, autoincrement=true) name = column(unicode(100), nullable=false) ...
then use paginate
users = user.query.paginate(1, 5, false)
the same error get_or_404() , first_or_404(). normal or first works usual.
i appreciate advice!
you calling paginate()
on query object provided sqlalchemy, pagination functionality available flask-sqlalchemy, subclasses base query object add , other features, including get_or_404()
, first_or_404()
methods found not work.
all happens because created database , model using sqlalchemy directly instead of using facilities provided flask-sqlalchemy. if according flask-sqlalchemy documentation find work fine.
Comments
Post a Comment