Showing posts from July, 2017

Localization of Dates and Times with Flask-Moment

Previous post: Get started with Python Flask Framework on IBM Bluemix

Flask-Moment is an extension for Flask applications that integrates moment.js into Jinja2 templates. Flask-Moment is installed with pip
For locally:$ pip install flask-moment For Bluemix: In requirements.txt add: Flask-moment==0.5.1 In Initialize Flask-Moment from flask_moment import Moment moment= Moment(app) Add moment.js into base template base.html
In templates/base.html: Import moment.js library {% block scripts %}{{ super() }}{{ moment.include_moment() }}{% endblock %} To work with timestamps Flask-Moment makes a moment class available to templates. In passes a variable called current_time to the template for rendering.
In Add a datetime variable. from datetime import datetime @app.route('/')defindex():return render_template(