Flask中如何使用html文件中现有的表单?
澳门第一娛乐城官网
澳门第一娛乐城官网
当前位置 : 澳门第一娛乐城官网 > 澳门第一娛乐城官网

Flask中如何使用html文件中现有的表单?

在网上找了一个现成的login html表单,在flask中如何不使用quick_form的方法直接处理html过来的表单数据。

{% extends "loginbase.html" %}

{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Please Sign In</h3>
                    </div>
                    <div class="panel-body">
                        <form role="form" action="{{ url_forauth.login }}" method="post">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="E-mail" name="email" type="email"  autofocus>

                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Password" name="password" type="password"  value="">
                                </div>
                                <div class="checkbox">
                                    <label>
                                        <input name="remember" type="checkbox" value="remember">Remember Me
                                        <a href="index.html" >   Not a member?</a>
                                    </label>
                                </div>
                                <!-- Change this to a button or input when using this as a form 
                                <a href="index.html" class="btn btn-lg btn-success btn-block">Login</a>-->
                                <input name="submit" class="btn btn-lg btn-success btn-block" type="submit" value="Submit">
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
@auth.route/login,methods=[GET,POST]
def login:
    print session
    if user_id in session:
        flash用户已登录!
        return redirect/
    form = LoginFormrequest.form
    if request.method == "POST":
        user = User.query.filter_byemail=request.form[email].first
        if remember not in request.form:
            print ok
        if user is not None and user.verify_passwordrequest.form[password]:
                if remember in request.form:
                    login_useruser,boolrequest.form[remember]
                else:
                    login_useruser
                flash登录成功
                return redirecturl_formain.index
        flash用户不存在或密码错误
        print 2
    return render_templateauth/login.html

表单的action会post一个请求到你服务器,注册一个处理这个url的post方法不就可以了?

广告位

澳门第一娛乐城官网