[Flask] Sharing a variable to all HTML pages

Mark Pors mark at pors.net
Thu Jul 14 02:31:25 EDT 2016


Have a look at context processors. You can inject variables or functions to
templates on the app or blueprint level.

See here at the bottom http://flask.pocoo.org/docs/0.11/templating/

Mark


On Thursday, July 14, 2016, John Robson <John.Robson at usp.br> wrote:

> Hi everyone,
>
> I would like to pass several variables to all HTML pages, how can I send a
> variable to all HTML pages, without pass it all the time through "
> *render_template*"? eg: sending "time" to all HTML pages
>
> *site.html*
> *Last Update: {{ update }}*
>
> *app.py*
> *  update = '2016-07-14 01:37:56'*
> *  return render_template('site.html', update=update)*
>
> But how to pass this value every time to all HTML pages automatically?
> Just:
> * return render_template('site.html')*
>
> And the value 'update' will be there.
>
> Thank you for helping,
> John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160714/3d9d953e/attachment.html>


More information about the Flask mailing list