How to update timestamp as a global variable in Jinja2? How to update timestamp as a global variable in Jinja2? flask flask

How to update timestamp as a global variable in Jinja2?


Use a context processor to inject values per request:

@app.context_processordef inject_template_globals():    return {        'nowts': datetime.datetime.utcnow(),    }

You generally want to use UTC time, not local time, for web servers. You never know where in the world your request comes from.