title: How to do a select query using flask and sqlalchemy?
body: <p>I'm new using flask and SQLAlchemy, I have a database in postgress, this database have table "data" 200 records, I want to do a Select statment but when I do it always give me the same error, this my code:</p>
  
  <p>This is my model.py</p>
  
  <pre><code>from sqlalchemy import Column, ForeignKey, Integer, String
  from sqlalchemy import create_engine
  from sqlalchemy.orm import scoped_session, sessionmaker
  from sqlalchemy.ext.declarative import declarative_base
  
  Base = declarative_base()
  
  class Data(Base):
      __tablename__ = 'data'
      ids = Column(Integer(), primary_key=True)
      customer_id = Column(String())
      inventory_id = Column(String())
      device_id = Column(String())
  
      def toJSON(self):       
          json = {
              "ids":self.ids,
              "customer_id":self.customer_id,
              "inventory_id":self.inventory_id,
              "device_id":self.device_id,     
          }
  
          return json
  </code></pre>
  
  <p>This is my flask application:</p>
  
  <pre><code>from flask_sqlalchemy import SQLAlchemy
  from flask import Flask, render_template, request
  from flask_cors import CORS, cross_origin
  from model import Data, Base
  
  app = Flask(__name__)
  CORS(app)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost/mydatabase'
  db = SQLAlchemy(app)
  data = []
  
  def index():
      test_data()
      return render_template("index.html",result = data)
  
  def test_data():
      sss = Base.Data.query.filter_by(ids=5).first()
      print sss
  
  app.add_url_rule('/', 'index', index)
  
  if __name__ == '__main__':
      app.run(debug = True, threaded=True)
  </code></pre>
  
  <p>This not works, and always have the same error: </p>
  
  <blockquote>
    <p>AttributeError: type object 'Base' has no attribute
    'psirt_alerts_view'</p>
  </blockquote>
  
  <p>How can I do this simply select?</p>
  
  <p>UPDATE:</p>
  
  <pre><code>[2017-02-14 12:02:29,980] ERROR in app: Exception on / [GET]
  Traceback (most recent call last):
    File "c:\python27\lib\site-packages\flask\app.py", line 1982, in wsgi_app
      response = self.full_dispatch_request()
    File "c:\python27\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "c:\python27\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
      return cors_after_request(app.make_response(f(*args, **kwargs)))
    File "c:\python27\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "c:\python27\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
      rv = self.dispatch_request()
    File "c:\python27\lib\site-packages\flask\app.py", line 1598, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "S:\ibm\ib.py", line 15, in index
      test_data()
    File "S:\ibm\ib.py", line 40, in test_data
      sss = Base.data.query.filter_by(ids=5).first()
  AttributeError: type object 'Base' has no attribute 'data'
  </code></pre>