PythonAnywhere Forums

Not understanding flask+sqlalchemy?

After many many attempts at integrating sqlalchemy orm into my rest server for my app, I've found myself again banging my head against a wall after having stripped everything down to be as bare as possible, and having it still not work. I've followed different guides online, and I can't find anything that I did differently, but using the code below results with "TypeError: 'Query' object is not callable", I've also gotten "TypeError: 'Item' object is not callable" Can anyone shed some light on what I'm missing here? I have a working version up and running using raw SQL calls on different database "engine" objects, but I'd really like to be able to grasp and utilize the orm side of SQLAlchemy
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from models import Item
from database import db_session, init_db

app = Flask(__name__)
db = SQLAlchemy(app)

def shutdown_session(exception=None):

def hello_world():
    #This didn't work.
    #item = Item.query.filter( == 'test').first()

    item = db_session.query(Item).filter( == 'test')
    return item
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from database import Base

class Item(Base):
    __tablename__= 'items'
    id = Column(Integer, primary_key=True)
    number = Column(Integer)
    name = Column(String(30))

    def __init__(self, number=None, name=None):
        self.number = number = name

    def __repr__(self):
        return '<Item %r>' % (
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('mysql://', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    from models import Item
    print("****************************************************************************Database Initiated********************************************")

My guess is you're reading the docs for one version and running a different version. Make sure that you're reading the docs for the version that you're using.