[Flask] 回复: Globally accessible variables in Flask

song xiaowei msn734506700 at live.com
Tue Apr 11 09:40:23 EDT 2017


 It calculated before request, used in the flask before request a decorator

发自网易邮箱大师

在2017年04月11日 20:39,badrihippo at gmail.com<mailto:badrihippo at gmail.com> 写道:
I know I figured this out sometime, but can't remember now. How does one make a variable that is automatically accessible to all views?

I mean like the current_user variable provided by Flask-Admin: it automatically calculates current_user and makes it available to the view for each request, without having to manually define it each time.

Basically, make it so that instead of...

@app.route('/example')
def example():
    my_var = something()

@app.route('/example/2')
def second_example():
    my_var = something()

...it automatically calculates my_var without having to manually define it in each view.

Okay, I hope that was clear. And thanks in advance!

—Badri/Hippo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170411/8cc1d7f1/attachment.html>


More information about the Flask mailing list