系统环境: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下面,供大家下载测试。

演示效果:

最新文章

  1. Jupyter Notebook 27绝技——27 Jupyter Notebook tips, tricks and shortcuts
  2. c#.net中参数修饰符ref,out ,params解析
  3. jquery中,size()和length()方法有啥区别
  4. mysqld_safe启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable
  5. jquery学习笔记---jquery插件开发
  6. ThinkPHP3.1快速入门(13)自动完成
  7. 通过正则获取url参数
  8. AutoFac使用方法总结:Part II
  9. iOS上传图片详解
  10. Http的定义及其基本概念介绍
  11. dhtmlx Gantt实例介绍分析
  12. PHP-不同Str 拼接方法性能对比 参考自https://www.cnblogs.com/xiaoerli520/p/9624309.html
  13. windows7,python3使用time.strftime()函数报ValueError: embedded null byte
  14. EasyUI datagrid.getSelections 没有返回正确的选择行数
  15. Linux系统启动和内核管理
  16. AltiumDesigner 网络标号放置技巧
  17. TwoSum:两数相加得0
  18. 切图js
  19. curl常用设置-涉及超时相关
  20. Redis 启动与授权

热门文章

  1. 重复测量的方差分析|Mauchly&#39;s Test of Sphericity|
  2. MAYA卸载/完美解决安装失败/如何彻底卸载清除干净MAYA各种残留注册表和文件的方法
  3. Dubbo与Nginx微服务架构
  4. 吴裕雄--天生自然python学习笔记:Python CGI编程
  5. 如果你的unordered_map头文件报错请看这里
  6. mongodb Map/reduce测试代码
  7. 关于HTTP请求GET和POST的区别
  8. JXJJOI2018_三题
  9. Ubuntu 16.04 PXE+kickstart部署系统
  10. HBase源码系列之HFile