如何在烧瓶中创建两阶段登录页面?

How to create two stage login page in flask?

我必须创建两个登录页面。一到 return 公司生产的所有巧克力和其他 return 个别巧克力的详细信息。

我已经试过了,但没用。

@app.route('/login', methods=['GET','POST']) 
@app.route('/login2', methods=['GET','POST'])
def login():
    error = None
    if request.method =='POST':
        un = request.form['username']
        pw = request.form['password']
        #check if username and password is correct and store the result in check
        if check == "error":
            error = 'Invalid Credentials. Please try again.'
        else:
            return redirect(url_for('login2'))
    return render_template('login.html', error = error)
if __name__ == '__main__':
   app.run(debug = True)
def login2():
    error = None
    if request.method =='POST':
        un = request.form['username']
        pw = request.form['password']
        #check if username and password is correct and store the result in check
        if check=="error":
            error = 'Invalid Credentials. Please try again.'
        else:
            return redirect(url_for('home'))
    return render_template('login2.html', error=error)

但这给出了一个错误,提示无法为 login2 构建 url。你是说登录吗? 我正在使用标准模板登录 html 页面

路由必须在它调用的函数的正上方,像这样:

@app.route('/login', methods=['GET','POST']) 
def login():
    error = None
    if request.method =='POST':
        un = request.form['username']
        pw = request.form['password']
        #check if username and password is correct and store the result in check
        if check == "error":
            error = 'Invalid Credentials. Please try again.'
        else:
            return redirect(url_for('login2'))
    return render_template('login.html', error = error)


@app.route('/login2', methods=['GET','POST'])
def login2():
    error = None
    if request.method =='POST':
        un = request.form['username']
        pw = request.form['password']
        #check if username and password is correct and store the result in check
        if check=="error":
            error = 'Invalid Credentials. Please try again.'
        else:
            return redirect(url_for('home'))
    return render_template('login2.html', error=error)


if __name__ == '__main__':
   app.run(debug = True)