Python Flask Flash无法正常工作 [英] Python Flask flash not working correctly
本文介绍了Python Flask Flash无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2行简单的代码:
@app.route('/contact/')
def contact():
flash('We are reachable at ')
return render_template('contact.html')
我在/contact收到我们可以联系到"消息,但它似乎是正常的短信.它没有背景色(蓝色)或几秒钟后消失. 其中contact.html包含
I get the message 'We are reachable at' at /contact but it appears are normal text message. It doesn't background color(blue) or disappears after seconds. where contact.html contains
{% 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 %}
推荐答案
请看一下.这可能对您有帮助
Please have a look at this. this might help you
<!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 Flash无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文