[Flask] Globally accessible variables in Flask

Corey Boyle coreybrett at gmail.com
Tue Apr 11 11:22:41 EDT 2017


I think you are looking for this.
http://flask.pocoo.org/docs/0.12/templating/#context-processors

On Tue, Apr 11, 2017 at 8:39 AM,  <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
> https://mail.python.org/mailman/listinfo/flask
>


More information about the Flask mailing list