python - Access data from existing table using Flask-Alchemy -
i know mysql , writing queries easy there time when becomes complicated , decided choose orm (sqlalchemy). using flask framework , using flask-sqlalchemy. documentation clear on how build model , insert data , how access model there in database. have database name collection has image table inside it.
model.py
from flask import flask flask_sqlalchemy import sqlalchemy sqlalchemy import table, column, integer, string, date, float import config # db class app = flask(__name__) app.config['sqlalchemy_database_uri'] = config.db_uri db = sqlalchemy(app)
config.py
dbhost = 'localhost' dbuser = 'root' dbpass = 'pass' dbname = 'collection' db_uri = 'mysql://' + dbuser + ':' + dbpass + '@' + dbhost + '/' +dbname
now access records:
model.py
data = db.session.execute("select * image;") r in data: print r
it print row. writing sql queries directly only. how access existing table data using flask-sqlalchemy?
Comments
Post a Comment