【简说Python WEB】Flask-Moment
2024-09-02 17:20:37
系统环境: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下面,供大家下载测试。
演示效果:
最新文章
- Jupyter Notebook 27绝技——27 Jupyter Notebook tips, tricks and shortcuts
- c#.net中参数修饰符ref,out ,params解析
- jquery中,size()和length()方法有啥区别
- mysqld_safe启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable
- jquery学习笔记---jquery插件开发
- ThinkPHP3.1快速入门(13)自动完成
- 通过正则获取url参数
- AutoFac使用方法总结:Part II
- iOS上传图片详解
- Http的定义及其基本概念介绍
- dhtmlx Gantt实例介绍分析
- PHP-不同Str 拼接方法性能对比 参考自https://www.cnblogs.com/xiaoerli520/p/9624309.html
- windows7,python3使用time.strftime()函数报ValueError: embedded null byte
- EasyUI datagrid.getSelections 没有返回正确的选择行数
- Linux系统启动和内核管理
- AltiumDesigner 网络标号放置技巧
- TwoSum:两数相加得0
- 切图js
- curl常用设置-涉及超时相关
- Redis 启动与授权
热门文章
- 重复测量的方差分析|Mauchly&#39;s Test of Sphericity|
- MAYA卸载/完美解决安装失败/如何彻底卸载清除干净MAYA各种残留注册表和文件的方法
- Dubbo与Nginx微服务架构
- 吴裕雄--天生自然python学习笔记:Python CGI编程
- 如果你的unordered_map头文件报错请看这里
- mongodb Map/reduce测试代码
- 关于HTTP请求GET和POST的区别
- JXJJOI2018_三题
- Ubuntu 16.04 PXE+kickstart部署系统
- HBase源码系列之HFile