我通过散布模型,蓝图来重新分解我的Flask应用程序,但我遇到了运行时错误.
def create_app():
app = flask.Flask("app")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
app.register_blueprint(api)
db.init_app(app)
db.create_all()
return app
Run Code Online (Sandbox Code Playgroud)
我有以下问题(示例项目在这里托管:https://github.com/chfw/sample):
Traceback (most recent call last):
File "application.py", line 17, in <module>
app = create_app()
File "application.py", line 12, in create_app
db.create_all()
File "\AppData\Roaming\Python\Python27\site-packages\flask_sqlalchemy\__init__.py", line 856, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "\AppData\Roaming\Python\Python27\site-packages\flask_sqlalchemy\__init__.py", line 836, in _execute_for_all_tables
app = self.get_app(app)
File "\AppData\Roaming\Python\Python27\site-packages\flask_sqlalchemy\__init__.py", line 809, in get_app
raise RuntimeError('application not registered on db
'RuntimeError: application not registered on db
instance and no application …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的应用工厂
db = SQLAlchemy()
def create_app(environment):
app = Flask(__name__)
app.config.from_object(config[environment])
db.init_app(app)
# ... etc
return app
Run Code Online (Sandbox Code Playgroud)
然后,我有一个脚本,它在应用程序的上下文之外提取CSV.这个脚本是一个每x小时运行一次的cron
我想以某种方式更新sqlite数据库应用程序正在使用.这可能吗?