Python 如何在2个函数中使用全局变量“采用”?

Python 如何在2个函数中使用全局变量“采用”?,python,flask,Python,Flask,我正在我的网站上为管理员进行otp身份验证,但当我试图在我的“adrelog”函数中使用这个“adopt”变量时,它给出了一个错误,即没有定义“adopt”变量。请帮助我了解如何在2个函数中使用此变量 python代码: #admin password reset logic adopt=" " @app.route("/admin_repass", methods=["GET","POST"]) def Admin

我正在我的网站上为管理员进行otp身份验证,但当我试图在我的“adrelog”函数中使用这个“adopt”变量时,它给出了一个错误,即没有定义“adopt”变量。请帮助我了解如何在2个函数中使用此变量

python代码:

#admin password reset logic
adopt=" "
@app.route("/admin_repass", methods=["GET","POST"])
def Admin_reset_pass():
    email=str(request.form.get("email"))
    details=db.execute("select email from admin_master_tbl").fetchall()
    message="email not found"
    message1="enter your otp"
    for det in details:
        if email in det[0]:
            string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
            length = len(string)
            otp=""
            for i in range(6) :
                otp += string[math.floor(random.random() * length)]
            global adopt
            adotp=otp
            msg = Message("Subject", recipients=[email])
            msg.body = adopt
            mail.send(msg)
            return render_template("admin_relogin.html", message=message1)
        else:
            return render_template("admin_pass_reset.html", message=message)

@app.route("/admin_otp", methods=["GET","POST"])
def adrelog():
    global adopt
    message="login successfull"
    cotp=str(request.form.get("otp"))
    if adopt==cotp:
        return render_template("index.html", message=message)
    else:
        return "login failed"
html代码1:

<html>
<body>
    <h2>{{message}}</h2>
    <form action="{{ url_for('Admin_reset_pass') }}" method="post" align:"center">
            <input type="text" name="email" placeholder="enter your mail for reset request">
                    <button>submit</button>
    </form>
</body>
</html>
html代码2:

<html>
<body>
    <form action="{{ url_for('adrelog') }}" method="post">
        <input type="text" name="otp" placeholder="enter your otp">
        <button>submit</button>
    </form>
</body>
</html>

您可以将它们存储在会话存储中,并在任何视图中访问它们。

谢谢您的回复。。。。。全局变量名中有一些我没有看到的错误。但现在它工作得很好。