Answer the question
In order to leave comments, you need to log in
What is the correct way to split a flask application into modules?
Good day to all!
When trying to make a large web application in flask, there was some problem when dividing the application into different files.
There is an app.py file which contains the following content:
app = Flask(__name__)
engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()
if __name__ == '__main__':
app.run(debug=True
class User(Base):
__tablename__ = 'payments'
id = Column(Integer, primary_key=True)
name = Column(String)
surname = Column(String)
second_name = Column(String)
@map_test.route('/test')
def test():
user = User()
user.name = 'name'
user.surname = 'sname'
session.add(user)
return Utils.getAnswer('ok')
from app import Base
from app import session
from entities.User import User
Answer the question
In order to leave comments, you need to log in
Take the following out of it app.py
into a separate file (for example, base/orm.py
):
engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question