问题
I've simple 2 line code :
@app.route('/contact/')
def contact():
flash('We are reachable at ')
return render_template('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 %}
回答1:
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 %}
and Do some styling with the css
p {
color:blue;
}
And add some jquery
to the code
$(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);
})
Hope this helps you.
来源:https://stackoverflow.com/questions/30497236/python-flask-flash-not-working-correctly