美文网首页
Flask-Moment 时间戳渲染

Flask-Moment 时间戳渲染

作者: 两份方糖红茶 | 来源:发表于2018-06-26 10:12 被阅读0次

Web程序使用Flask-Moment显示本地化日期与时间

在hello.py中初始化Flask-Moment

from flask_moment import Moment
moment = Moment(app)

在templates/base.html中引入moment.js库

{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}

在hello.py中加入一个datetime变量

from datetime import datetime
@app.route('/')
def index():
return render_template('index.html',current_time=datetime.utcnow())

在templates/index.html当中渲染current_time

{% extends 'base.html' %}
{% block page_content %}
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p> 
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
{% endblock %}

实现效果:
第一行显示当前时间,第二行显示呆在这个页面的时间


时间渲染效果

相关文章

  • Flask-Moment 时间戳渲染

    Web程序使用Flask-Moment显示本地化日期与时间 在hello.py中初始化Flask-Moment 在...

  • 如何渲染一个组件?

    在组件上定义个key,这个key用时间戳来更新值,来渲染组件。

  • Fask-Moment 时间渲染失效,使用CDN

    最经在学flask 一个问题: 在使用flask-moment 本地化日期和时间时,代码正常,时间日期不显示 详细...

  • uniapp时间戳转换成年月日时分秒的格式

    后端返回的时间格式是时间戳,需要以年月日的格式渲染在前端界面由于uniapp是基于vue的,所以对于时间的处理。我...

  • 时间戳

    很多网站在发布版本之前,都会在请求地址加一个时间戳进行版本更新。这样是版本更新时避免之前用户浏览器的缓存影响。请求...

  • 时间戳

    一. 关于[NSDatedate] 的问题 NSDate*date=[NSDatedate]; NSLog(@"d...

  • 时间戳

    时间戳 ios 在webView中的网页中,时间戳使用时(js)格式要用/ 而不能是-如 应该使用2018/09...

  • 时间戳

    时间戳转换成距此刻多久

  • 时间戳

    // 获取当前时间戳 + (NSString *)getCurrentTime { NSDate *sendd...

  • 时间戳

    // 获取当前时间戳(以s为单位) var timestamp = Date.parse(new Date());...

网友评论

      本文标题:Flask-Moment 时间戳渲染

      本文链接:https://www.haomeiwen.com/subject/nudpyftx.html