Browse Source

Chapter 3: Dates and times with Flask-Moment (3e)

master
T. Meissner 6 years ago
parent
commit
5ffd385c15
3 changed files with 12 additions and 1 deletions
  1. +5
    -1
      hello.py
  2. +5
    -0
      templates/base.html
  3. +2
    -0
      templates/index.html

+ 5
- 1
hello.py View File

@ -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/<name>')


+ 5
- 0
templates/base.html View File

@ -34,4 +34,9 @@
<div class="container">
{% block page_content %}{% endblock %}
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}

+ 2
- 0
templates/index.html View File

@ -6,4 +6,6 @@
<div class="page-header">
<h1>Hello World!</h1>
</div>
<p>The local date and time is {{ moment(current_time).format("MMMM Do YYYY, HH:mm:ss")}}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
{% endblock %}

Loading…
Cancel
Save