python - moment (current_time).format("LLL")在网页中不显示时间
阿神
阿神 2017-04-17 17:30:20
0
3
865
<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>
阿神
阿神

闭关修行中......

모든 응답(3)
巴扎黑

需要在base.html载入moment.js库的,是不是忘记了?

大家讲道理

嗯我最近也在看这个,遇到和你一样的问题,不知道你解决了没有
我试了一下,如果在 head引入js就可以
{% block head %}
{{ moment.include_jquery() }}
{{ moment.include_moment() }}
{{ moment.lang("zh-CN") }}
{% endblock %}
但是这样样式会冲突。

阿神

题主你好,请问你现在这个问题解决了吗? 我也在看《Flask Web开发》这本书,遇到了同样的问题。

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!