我有两行简单的代码:
@app.route('/contact/')
def contact():
flash('We are reachable at ')
return render_template('contact.html')我在/contact上收到消息‘我们可以到达’,但它看起来是普通的文本消息。它不会显示背景颜色(蓝色),也不会在几秒钟后消失。其中contact.html包含
{% extends "layout.html" %}
{% block title %}Contact{% endblock title %}
{% block body %}
<h2> Contact Us </h2>
Your email address must be valid as this is where reply
will be sent. We do not share this address with anybody.
{% endblock body %}发布于 2015-05-28 13:20:54
请看看这个。这可能会对你有帮助
<!doctype html>
<title>My Application</title>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class="flashes">
{% for message in messages %}
<div class="message_flash">{{ message }}</div>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% block body %}
{% endblock %}并使用css进行一些样式设置
p {
color:blue;
} 并在代码中添加一些jquery
$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 5 sec. and then will fire
// $(".message_flash").hide() function
setTimeout(function() {
$(".message_flash").hide('blind', {}, 500)
}, 5000);
}) 希望这对你有帮助。
发布于 2021-04-01 12:07:27
我认为你需要的是一些CSS让它看起来更漂亮。如果您向base.html/layout.html添加一些引导程序,则可以在base.html/layout.html中执行此操作。
{% with messages=get_flashed_messages(with_categories=true) %}
{% for category, message in messages %}
<div class='alert alert-{{category}} text-center alert-dismissible fade show m-auto'>
{{ message }}
</div>
{% endfor %}
{% endwith %}现在,每当你要显示一条闪光消息时,在你的路线中这样做。
@app.route('/')
def index():
flash('Your message here', 'your bootstrap category[eg:success, primary, etc]')
return reder_template('contact.html')https://stackoverflow.com/questions/30497236
复制相似问题