简体   繁体   English

为什么我的 flash 消息没有显示正确的颜色和按钮?

[英]Why are my flash messages not displaying the correct colours and button?

My flash messages aren't showing the correct colours and the 'x' button is in the wrong place.我的 flash 消息没有显示正确的颜色,并且“x”按钮在错误的位置。 what have i done wrong?我做错了什么?

this is from my base.html file:这是来自我的 base.html 文件:

 {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} {% if catgeory == 'error' %} <div class="alert alert-danger alter-dismissable fade show" role="alert"> {{ message }} <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">&times;</span> </button> </div> {% else %} <div class="alert alert-success alter-dismissable fade show" role="alert"> {{ message }} <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">&times;</span> </button> </div> {% endif %} {% endfor %} {% endif %} {% endwith %}

This is from my auth.py file:这是来自我的 auth.py 文件:

 @auth.route('/sign-up', methods=['GET', 'POST']) def sign_up(): if request.method =='POST': firstName = request.form.get('firstName') email = request.form.get('email') password1 = request.form.get('password1') password2 = request.form.get('password2') if len(firstName) < 2: flash('First Name must be greater than 1 character.', category='error') elif len(email) < 4: flash('Email must be greater than 3 characters.', category='error') elif password1:= password2. flash('Passwords don\'t match,': category='error') elif len(password1) < 7. flash('Password must be atleast 7 characters,': category='error') else, flash('Account created.', category='success') return render_template("sign_up.html")

I think you just have typos in your code.我认为您的代码中只有拼写错误。 For example "category" is written as "catgeory" in if statement in base.html file.例如“category”在base.html文件的if语句中写成“catgeory”。 Also take a look at your div tag.还要看看你的 div 标签。 The correct bootstrap styling is class="alert alert-warning alert-dismissible fade show" .正确的引导样式是class="alert alert-warning alert-dismissible fade show" Probably the x button will be at the right place if you edit "alter-dismissable".如果您编辑“alter-dismissable”,x 按钮可能会在正确的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM