Use the template context processor to pass the current date to each template and then display its year attribute.
from datetime import datetime @app.context_processor def inject_now(): return {'now': datetime.utcnow()}
{{ now.year }}
Or pass an object using render if it is not needed in most templates.
return render_template('show.html', now=datetime.utcnow())
source share