首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python Flask闪存无法正常工作

Python Flask闪存无法正常工作
EN

Stack Overflow用户
提问于 2015-05-28 12:24:11
回答 2查看 12.6K关注 0票数 1

我有两行简单的代码:

代码语言:javascript
运行
复制
@app.route('/contact/')
def contact():
  flash('We are reachable at ')
  return render_template('contact.html')

我在/contact上收到消息‘我们可以到达’,但它看起来是普通的文本消息。它不会显示背景颜色(蓝色),也不会在几秒钟后消失。其中contact.html包含

代码语言:javascript
运行
复制
{% 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 %}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-28 13:20:54

请看看这个。这可能会对你有帮助

代码语言:javascript
运行
复制
<!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进行一些样式设置

代码语言:javascript
运行
复制
p {
 color:blue;  
 } 

并在代码中添加一些jquery

代码语言:javascript
运行
复制
$(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);
})   

希望这对你有帮助。

票数 10
EN

Stack Overflow用户

发布于 2021-04-01 12:07:27

我认为你需要的是一些CSS让它看起来更漂亮。如果您向base.html/layout.html添加一些引导程序,则可以在base.html/layout.html中执行此操作。

代码语言:javascript
运行
复制
{% 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 %}

现在,每当你要显示一条闪光消息时,在你的路线中这样做。

代码语言:javascript
运行
复制
@app.route('/')
def index():
   flash('Your message here', 'your bootstrap category[eg:success, primary, etc]')
   return reder_template('contact.html')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30497236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档