我有简单的两行代码:
@app.route('/contact/')
def contact():
flash('We are reachable at ')
return render_template('contact.html')
我在/contact 收到消息“We are reachable at”,但它看起来是正常的文本消息。它没有背景颜色(蓝色)或在几秒钟后消失。 其中 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 %}
最佳答案
请看这个。这可能对你有帮助
<!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);
})
希望对你有帮助。
关于Python Flask 闪存无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30497236/