python flask 消息闪现
1、views 示例
from flask import render_template, redirect, url_for, Flask, flash, session, request
@admin.route("/account/del/<int:id>/", methods=["GET"])
@admin_login_req
def account_del(id=None):
from app.models import db
print(id)
account = Account.query.filter_by(id=id).first_or_404()
print(account)
db.session.delete(account)
db.session.commit()
flash("删除记录成功!", "ok") # 消息闪现
return redirect(url_for('admin.account_list', page=1))
2、模板示例
{% for msg in get_flashed_messages(cateGory_filter=["ok"]) %}
<div class="king-notice2 king-notice-success notice-borders">
<i class="fa fa-check-circle"></i>
<div class="notice-text">
<p>{{ msg }}</p>
</div>
</div>
{% endfor %}
消息闪现参考文档:Http://www.pythondoc.com/flask/patterns/flashing.html
相关文章