一、導入安裝html
二、在類中引入falsk_moment模塊前端
# -*- coding:utf-8-*- from flask_script import Manager from flask import Flask, render_template from flask_bootstrap import Bootstrap from flask_moment import Moment from datetime import datetime print app = Flask(__name__) # 啓動配置 # app.config.from_object('config') # 定義Manager對象 manager = Manager(app) # 定義Bootstrap對象 bootstrap = Bootstrap(app) # 定義Moment對象 moment = Moment(app) @app.route('/') def index(): current_time = datetime.utcnow() print current_time return render_template('index.html', current_time=current_time) @app.route('/user/<name>') def user(name): return render_template('user.html', name=name) @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 @app.errorhandler(500) def internal_server_error(e): return render_template('500.html'), 500 if __name__ == "__main__": app.run(debug=True)
三、因爲有引入bootstrap前端框架,內置的有jquery與moment,直接引用includejquery
<!--引入Moment依賴庫--> {{ moment.include_jquery() }} {{ moment.include_moment() }}
四、在html中編輯時間與格式化flask
<body> <h1>hello world!--->覃光林</h1> <p>當前時間:{{ moment(current_time).format('YYYY年M月D日, h:mm:ss a'+'') }}</p> <p>初始化訪問時間:{{ moment(current_time).fromNow(refresh=True) }}</p> </body>