Heim > Fragen und Antworten > Hauptteil
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
在网站中不现实时间
然而直接打
<p>{{ current_time }}</p>
会显示时间
hello.py
from flask import Flask, render_template
from flask import Flask
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap
from flask.ext.moment import Moment
from datetime import datetime
app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
now = datetime.now()
@app.route('/')
def index():
return render_template('index.html',current_time=datetime.utcnow())
@app.route("/user/<name>")
def user(name):
return render_template("user.html", name = name )
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html"), 404
if __name__ == "__main__":
app.run(debug = True)
manager.run()
index.html
templates/index.html: Jinja2
<h1>Hello world!</h1>
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
<p>{{ current_time }}</p>
大家讲道理2017-04-17 17:32:20
嗯我最近也在看这个,遇到和你一样的问题,不知道你解决了没有
我试了一下,如果在 head引入js就可以
{% block head %}
{{ moment.include_jquery() }}
{{ moment.include_moment() }}
{{ moment.lang("zh-CN") }}
{% endblock %}
但是这样样式会冲突。