zoukankan      html  css  js  c++  java
  • 测开之路一百三十六:错误消息闪回提示

    错误消息提示:flask.flash

    视图

    app.secret_key = 'qoihf2397r21380r2/./ad'  # 加密的安全码,越复杂越好,flask后台自动进行加密


    @app.route('/login/', methods=['GET', 'POST'])
    def login():
    """ 登录 """
    if request.method == 'POST':
    username = request.form.get('username')
    password = request.form.get('password')
    sql = 'select count(*) as [Count] from UserInfo where username = ? and password = ?'
    result = query_sql(sql, (username, password), True)
    if int(result.get('Count')) > 0:
    return redirect(url_for('list'))
    flash('用户名或密码错误')
    return render_template('login.html')

    login.html

    {% extends 'base.html' %}

    {% block main_content %}

    <!--登录界面-->
    <div class="row">
    <div class="col-md-6 col-md-offset-3">
    <div class="panel panel-default">
    <div class="panel-heading">
    <h4>登录</h4>
    </div>
    <div class="panel-body">
    <form action="#" class="form-horizontal" method="post">
    <div class="col-md-10 col-md-offset-1">
    <!--错误消息闪现-->
    {% with messages = get_flashed_messages() %}<!-- 获取flash返回的消息,语法由jinja2提供 -->
    {% if messages %}
    {% for msg in messages %}
    <div class="alert alert-warning">
    <a href="#" class="close" data-dismiss="alert">&times;</a>
    {{ msg }}
    </div>
    {% endfor %}
    {% endif %}
    {% endwith %}
    <div class="form-group">
    <label for="username" class="col-md-3">用户名:</label>
    <div class="col-md-7">
    <input type="text" class="form-control" name="username" id="username">
    </div>
    </div>
    <div class="form-group">
    <label for="password" class="col-md-3">密码:</label>
    <div class="col-md-7">
    <input type="text" class="form-control" name="password" id="password">
    </div>
    </div>
    <div class="form-group">
    <div class="col-md-10 col-md-offset-3">
    <input type="submit" class="btn btn-primary" value="登录">
    </div>
    </div>
    </div>

    </form>
    </div>
    <div class="footer">
    &copy;版权所有
    </div>
    </div>
    </div>
    </div>


    {% endblock %}

    登录

  • 相关阅读:
    ubuntu segmentation fault 段错误
    css配合js模拟的select下拉框
    让IE6下支持固定定位
    max-height,min-height在IE下不支持的解决方法
    图片居中
    完美运动框架,随意调用,兼容性好
    JS创建Ajax的XMLHttpRequest对象的通用方法
    JS兼容性问题(FF与IE)
    css样式
    html之marquee详解[转]
  • 原文地址:https://www.cnblogs.com/zhongyehai/p/11462468.html
Copyright © 2011-2022 走看看