东瑜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

系统环境:Ubuntu 18.04.1 LTS

Python使用的是虚拟环境:virutalenv

Python的版本:Python 3.6.9

【简说Python WEB】Flask-Moment

Javascript有一个非常不错的优秀的客户端开源库,Moment.js。在客户端的浏览器上加载时间。

安装Flask-Moment

$ pip install Flask-Moment

templates/base.html引入Moment.js

{% block scripts %}
{{ super() }}
{{moment.include_moment() }}
{{moment.locale('zh-cn') }}
{% endblock %}

其中:moment.locale('zh-cn')代表支持中文,具体参考文档:http://momentjs.cn/

hello.py`moment实例初始化

from flask_moment import Moment

moment = Moment(app)

hello.py添加datatime变量

from datetime import datetime

def user(name):
    return render_template('user.html', name=name,current_time=datetime.utcnow())

user.html渲染moment

<p>当前时间:{{ moment(current_time).format('LLL') }}.</p>

源码不贴了,以后放到github下面,供大家下载测试。

演示效果:

posted on 2020-03-19 21:20  东瑜  阅读(353)  评论(0编辑  收藏  举报
\\页脚html代码