From 5ffd385c154994270f863a9d8f810295dc00bb25 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Thu, 11 Oct 2018 22:20:38 +0200 Subject: [PATCH] Chapter 3: Dates and times with Flask-Moment (3e) --- hello.py | 6 +++++- templates/base.html | 5 +++++ templates/index.html | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hello.py b/hello.py index 83940c1..3b21921 100644 --- a/hello.py +++ b/hello.py @@ -1,9 +1,13 @@ +from datetime import datetime from flask import Flask, render_template from flask_bootstrap import Bootstrap +from flask_moment import Moment + app = Flask(__name__) bootstrap = Bootstrap(app) +moment = Moment(app) @app.errorhandler(404) @@ -18,7 +22,7 @@ def internal_server_error(e): @app.route('/') def index(): - return render_template('index.html') + return render_template('index.html', current_time=datetime.utcnow()) @app.route('/user/') diff --git a/templates/base.html b/templates/base.html index 6e380e5..34ad57a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -34,4 +34,9 @@
{% block page_content %}{% endblock %}
+{% endblock %} + +{% block scripts %} +{{ super() }} +{{ moment.include_moment() }} {% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 122059b..06afd59 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,4 +6,6 @@ +

The local date and time is {{ moment(current_time).format("MMMM Do YYYY, HH:mm:ss")}}.

+

That was {{ moment(current_time).fromNow(refresh=True) }}

{% endblock %} \ No newline at end of file