zoukankan      html  css  js  c++  java
  • 【简说Python WEB】Flask-Moment

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

    演示效果:

  • 相关阅读:
    mplayer命令行模式下的使用方法
    CentOS安装wireshark
    CentOS查看系统信息
    测试理论1
    单例模式
    接口测试
    rabbitmq
    redis数据库
    时间模块
    charles抓取数据
  • 原文地址:https://www.cnblogs.com/zhangshengdong/p/12527287.html
Copyright © 2011-2022 走看看