Python Flask闪存无法正常工作

web*_*org -2 python jinja2 flask

我有简单的2行代码:

@app.route('/contact/')
def contact():
  flash('We are reachable at ')
  return render_template('contact.html')
Run Code Online (Sandbox Code Playgroud)

我在/ 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 %}
Run Code Online (Sandbox Code Playgroud)

Sur*_*lwe 8

请看看这个.这可能对你有帮助

<!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 %}
Run Code Online (Sandbox Code Playgroud)

和做一些造型 css

p {
 color:blue;  
 } 
Run Code Online (Sandbox Code Playgroud)

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);
})   
Run Code Online (Sandbox Code Playgroud)

希望这对你有所帮助.