我有两行简单的代码:
@app.route('/contact/')
def contact():
flash('We are reachable at ')
return render_template('contact.html')我在/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 %}发布于 2021-04-01 12:07:27
我认为你需要的是一些CSS让它看起来更漂亮。如果您向base.html/layout.html添加一些引导程序,则可以在base.html/layout.html中执行此操作。
{% 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 %}现在,每当你要显示一条闪光消息时,在你的路线中这样做。
@app.route('/')
def index():
flash('Your message here', 'your bootstrap category[eg:success, primary, etc]')
return reder_template('contact.html')https://stackoverflow.com/questions/30497236
复制相似问题