欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Flask-Moment本地化日期和时间显示不正常

程序员文章站 2022-07-12 16:03:44
...

 这几天一直在继续学习,<<flask web开发>>中第3.6节,按照书上的实例,代码如下:

bootstrap/base.html

<html>
<head>
 {% block head %}
 <title>{% block title %}{% endblock %}-My Application</title>
 {% endblock %}
</head>

<body>
 {% block body %}
 {% endblock %}
</body>
</html>

 

templates/base.html(注意和上面的不是一个文件)

{% extends "bootstrap/base.html" %}

{% block title %}Flasky{% endblock %}

{% block head %}
{{ super() }}
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
{% endblock %}

{% block navbar %}
<div class="navbar navbar-inverse" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Flasky</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">Home</a></li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}

{% block content %}
<div class="container">
    {% block page_content %}{% endblock %}
</div>
{% endblock %}

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

 

templates/index.html

{% extends "base.html" %}

{% block title %}Flasky{% endblock %}
{% block content %}
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}.</p>
<h3>{{ current_time }}.</h3>
{% endblock %}

hello.py

from datetime import datetime
from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_script import Manager

 

moment = Moment(app)
bootstrap = Bootstrap(app)
manager = Manager(app)

@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


@app.route('/')
def index():
    return render_template('index.html')

@app.route('/user/<name>')
def user(name):
    return render_template('user.html', name=name)

 

最后运行以后,在页面显示不出来书上的效果,

Flask-Moment本地化日期和时间显示不正常
            
    
    博客分类: python3

各种百度,加flask群,各种修改,都不行!我用的是IE浏览器,最后实在没办法了,我下了一个火狐浏览器,调试一下试试吧,谁知道,一运行,没有问题!真是日了狗了,IE果然强!最后,如果哪位大神在IE下调试成功的话,请告诉我一声!

 

 

 

  • Flask-Moment本地化日期和时间显示不正常
            
    
    博客分类: python3
  • 大小: 1.9 KB