flask中flash不显示问题
2016-08-17 14:01
288 查看
flask中有个flash功能用来提示用户一些信息,比如用户退出登陆或者登陆用户名密码不匹配等。。。
在开发过程中,后台里边写入消息提示flash,但是触发了flash条件但是页面并没有显示需要提示的信息。
原因:flash消息需要在模板中进行渲染。
例子:用方法get_flashed_messages()来获取后台堆积的flash消息,然后用一个for循环来显示需要提示的信息。
应用代码:
@auth.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user, form.remember_me.data)
return redirect(request.args.get('next') or url_for('main.index'))
flash('无效用户名或密码.')
return render_template('auth/login.html', form=form)
模板渲染:
<div class="container">
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ message }}
</div>
{% endfor %}
{% block page_content %}{% endblock %}
</div>
在开发过程中,后台里边写入消息提示flash,但是触发了flash条件但是页面并没有显示需要提示的信息。
原因:flash消息需要在模板中进行渲染。
例子:用方法get_flashed_messages()来获取后台堆积的flash消息,然后用一个for循环来显示需要提示的信息。
应用代码:
@auth.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user, form.remember_me.data)
return redirect(request.args.get('next') or url_for('main.index'))
flash('无效用户名或密码.')
return render_template('auth/login.html', form=form)
模板渲染:
<div class="container">
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ message }}
</div>
{% endfor %}
{% block page_content %}{% endblock %}
</div>
相关文章推荐
- 关于Firefox中的Flash不可以显示透明效果的问题
- flash不显示的问题
- flash动态文本中文显示问题
- 转载的:flash 中文不显示问题
- ubuntu firefox flash显示乱码问题的解决方法
- 在网页内无法显示Flash的问题的解决方法
- flash在360、腾讯浏览器下的显示出错问题
- IIS启用Gzip压缩造成OpenFlashChart不能正常显示问题及解决方法
- 解决ubuntu下Firefox Flash文字乱码或不能显示的问题
- 解决 flash 10 中文字体显示成方块的问题
- 关于xp系统flash显示虚框问题
- 解决linux下jdk1.5中flash等显示中文为方块的问题
- flash 系统字体显示问题
- (转)解决flash中文显示方块的问题&gedit中文乱码问题
- swf在flash里面正常显示。本地打开无法访问的问题(读本地config文件)
- 解决FireFox访问Google Analytics不能正常显示Flash的问题
- 解决Chrome中Flash无法显示的问题
- [转]解决Linux下Firefox Flash文字乱码或不能显示的问题
- 问题:IE浏览器打开某些网页时不显示FLASH
- 声音冲突及firefox中flash中汉字显示问题解决