按照书上的提示对代码做了相关改变后启动hello.py 网页发生了改变,但却没有显示时间。
相关的templates/index.html代码:
<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>
<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>
这样可以显示时间,但是时间跟本地时间不一样。
但是index.html中第三句fromNow()渲染相对时间戳也没有起作用。
hello.py代码:
from flask_bootstrap import Bootstrap
from flask_script import Manager #把命令行解析功能添加到hello.py中
from flask import Flask
from flask import render_template
from flask_moment import Moment
from datetime import datetime
app = Flask(__name__)
moment = Moment(app)
bootstrap = Bootstrap(app)
manager = Manager(app)
@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
@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'), 500
#if __name__ == '__main__':
# app.run(debug=True)
if __name__ == '__main__':
manager.run()
网上找了一个正确显示的例子:
求解????
我把开发者工具里右边箭头指向的框里的√去掉时间就显示出来了
---------------------------------------------------------------------------------------
我把index.html里面加了点代码,时间能够正常显示了,反正暂时还不知道为什么
index.html代码