Flask应用程序中的用户数据

时间:2019-12-15 06:17:30

标签: python flask

我的应用程序用户的个人数据(登录名和密码)在哪里以及如何保存在Flask上?

def login():
form = LoginForm()
if form.validate_on_submit():
    flash('Login requested for user {}, remember_me={}'.format(
        form.username.data, form.remember_me.data))


    return redirect('/index')
return render_template('login.html', title='Sign In', form=form)

1 个答案:

答案 0 :(得分:0)

从登录页面获取用户名和密码,并对照数据库中的值进行检查,如果正确,请继续进行操作

   from flask_login import login_user
   @app.route('/login', method=['post', 'get'])
    def login():
        form = LoginForm(request.form)
        current_app.logger.info("Hello from the home page!")
        # Handle logging in
        current_app.logger.info("this is form {} {}".format(form, form.username))
        if request.method == "POST":
            current_app.logger.info("post request is made")

            if form.validate_on_submit():
                login_user(form.user)
                flash("You are logged in.", "success")
                redirect_url = request.args.get("next") or url_for("public.dashboard")
                return redirect(redirect_url)
            else:
                flash_errors(form)
        return render_template("login.html", form=form)