【发布时间】:2012-03-30 15:37:10
【问题描述】:
我正在尝试从蓝图(我将在模板中使用的函数)在 Jinja 环境中添加一个函数。
Main.py
app = Flask(__name__)
app.register_blueprint(heysyni)
MyBluePrint.py
heysyni = Blueprint('heysyni', __name__)
@heysyni.route('/heysyni'):
return render_template('heysyni.html', heysini=res_heysini)
现在在 MyBluePrint.py 中,我想添加如下内容:
def role_function():
return 'admin'
app.jinja_env.globals.update(role_function=role_function)
然后我就可以在我的模板中使用这个功能了。我不知道如何访问该应用程序,因为
app = current_app._get_current_object()
返回错误:
working outside of request context
我怎样才能实现这样的模式?
【问题讨论】: