[Flask] Globally accessible variables in Flask
Young,Spencer P
spenceryoung at ufl.edu
Tue Apr 11 09:08:00 EDT 2017
You probably want to take a look at the request context and proxies. IIRC 'current_user' is a proxy pushed onto the request context.
http://flask.pocoo.org/docs/0.12/reqcontext/
-Spencer
Sent from my iPhone
On Apr 11, 2017, at 8:44 AM, "badrihippo at gmail.com<mailto:badrihippo at gmail.com>" <badrihippo at gmail.com<mailto:badrihippo at gmail.com>> wrote:
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
_______________________________________________
Flask mailing list
Flask at python.org<mailto:Flask at python.org>
https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170411/4a39e9c6/attachment-0001.html>
More information about the Flask
mailing list