python - Changing jinja_env from a blueprint -


i trying register new jinja global on blueprint using blueprint object. however, appears blueprint objects not have jinja_env attributes; how can register new jinja global attributes?

here's __init__.py of blueprint, not work:

from flask import blueprint, current_app  uploader = blueprint('uploader', __name__, template_folder='templates')  . import views . import models  current_app.jinja_env.globals['form_token'] = views.generate_form_token 

nor this:

uploader.jinja_env.globals['form_token'] = views.generate_form_token 

use blueprint.app_template_global decorator register global function jinja env.

uploader.app_template_global(views.generate_form_token) 

or in views.py:

@uploader.app_template_global def generate_form_token():     pass 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -