Kaworu
Active Coder
Hi!
I am slowly learning Flask framework. When trying to show the current time (and time that had passed since the page got generated) I encountered an error.
My app.py looks like this:
My index.html in templates folder looks like this:
And what I get is this:
I dunno what I am doing wrong, being honest. I would appreciate some help.
I am slowly learning Flask framework. When trying to show the current time (and time that had passed since the page got generated) I encountered an error.
My app.py looks like this:
Python:
from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from datetime import datetime
app = Flask(__name__)
bootstrap = Bootstrap(app)
moment = Moment(app)
@app.route('/')
def index():
return render_template("index.html",
current_time=datetime.utcnow())
# some other code, not important right now
My index.html in templates folder looks like this:
HTML:
<!doctype html>
<html>
<head>
<title>Flasky - index from template</title>
</head>
<body>
<h1 align="center">Index from template</h1>
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}.</p>
</body>
</html>
And what I get is this:
I dunno what I am doing wrong, being honest. I would appreciate some help.