1.在settings.py中定义了常量,如何在别的python中使用
导包 from flask import current_app
current_app.config.get("XXX")
2.python 方法接收可变参时 传入tuple报错tuple index out of range
以format(self, *args, **kwargs) 为例 arg_list为list
format(arg_list)报错tuple index out of range
修改为format(*arg_list)
3.No application found. Either work inside a view function or push an application context
代码缺失上下文环境
//原代码
init_schedule()
//修改为代码
with app.app_context():
init_schedule()
4.python对None的判断 可以将None理解为false(None等于false)
5.python在使用flask时RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/
解决办法(1)在app中设置 db.app = app 或者在db.py中设置db = SQLAlchemy() 改为 db = SQLAlchemy(app)
6.python Flask中RE:Working outside of application context
使用with语句
from flask import Flask, current_app
app = Flask(__name__)
with app.app_context(): # Create an :class:`~flask.ctx.AppContext`.
host = current_app.config.get('XXX')