w00d
w00d

Reputation: 5596

Python Flask make a WTForm available to all templates

I have a login form that should appear in all templates, so It's not convenient to pass it as parameter in every render_template(). I tried to put it in a environment globals like this:

app = Flask(__name__)
app.jinja_env.globals['loginform'] = LoginForm()

But it throws exception: raise RuntimeError('working outside of application context')

How to do this correctly in Flask ?

Upvotes: 1

Views: 441

Answers (1)

jeverling
jeverling

Reputation: 2084

I think you should be able to achieve that by using a Context Processor:
http://flask.pocoo.org/docs/templating/#context-processors

Upvotes: 3

Related Questions