在使用Flask进行web开发的时候,因为我的数据库已经有表了,所以我用 flask-sqlacodegen将存在的数据库表转化成model.py,部分文件如下:
# coding: utf-8
from sqlalchemy import BigInteger, Column, Date, DateTime, Float, Integer, Numeric, String
from sqlalchemy.schema import FetchedValue
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class TBiomas(Base):
__tablename__ = 't_biomass'
id = Column(Integer, primary_key=True)
plant_id = Column(Integer)
WP_norm = Column(Numeric(10, 4))
fwp = Column(Numeric(10, 4))
在__init__文件中,我写入了
from flask_sqlalchemy import SQLAlchemy
from flask import Flask
app = Flask(__name__)
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
from app import views
viws.py目前这样写的 错误原因:
AttributeError: type object 'TBiomas' has no attribute 'query'
from app.models import TBiomas
from app import app, db
@app.route('/')
def index():
results = TBiomas.query.all()
db.session.commit()
print(results)
请问该如何将__init__.py、models.py、views.py连接起来呢?