如何传递值以在烧瓶中将重定向(url_for())从一种方法返回到另一种方法

时间:2020-06-22 20:59:00

标签: python postgresql flask

  • 我有一种方法可以从数据库中提取电子邮件ID和手机号码。
  • 我正在使用POSTGRES作为数据库并使用python语言。出于OTP的目的,我需要将该值传递给第二种方法,但我遇到了错误。
@app.route("/", methods=['GET', 'POST'])
def userlogin():
            sql_mobile_query = """SELECT users.phone FROM users WHERE users.email = %s"""
            cursor.execute(sql_mobile_query, record_to_search)
            mobile = cursor.fetchone()
            mobile_new = mobile[0]
            sql_email_query = """SELECT users.email FROM users WHERE users.email = %s"""
            cursor.execute(sql_email_query, record_to_search)
            email = cursor.fetchone()
            email_new = email[0]
            connection.commit()
            if(role == ('Admin',) and eotp == ('False',) and motp == ('False')):
                return "No need of OTP"
            else:
                return redirect(url_for('otp', email=email_new , mobile=mobile_new))
            connection.commit()
            print("Logged in sucessfully")
  • 我还有另一种方法,需要使用从上述userlogin()方法传递过来的此方法来访问电子邮件ID和手机号码
@app.route("/otp/<email>/<mobile>", methods=['GET', 'POST'])
def otp(email, mobile):
    email = email
    mobile = mobile
    print(email, mobile)
    return render_template("otp_screen.html")
  • 现在我在执行过程中遇到此错误 enter image description here

0 个答案:

没有答案