错误通过烧瓶传递变量python Web应用程序

时间:2020-05-17 17:56:59

标签: python function web flask

我是编程的新手,我知道像wtforms这样有用的东西,但是我想在深入学习之前先进行一些练习。

想法是创建一个注册用户的Web应用程序,我认为最好将此逻辑与应用程序代码区分开。

问题是我收到此错误消息: TypeError:register()接受0个位置参数,但给出了3个 我很困惑,因为函数声明有位置参数,我写的代码是:

应用代码:

@app.route("/register", methods=["POST", "GET"])
def register():
    if request.method =="POST":
        if not user_name or not password or not pass_confirm:
            return ("all fields are mandatory, also consider to active javaScript for a better expirience",404)
    user_name = request.form.get("user_name")
    password = request.form.get("password")
    pass_confirm = request.form.get("user_name")
    register(user_name, password, pass_confirm)
    return render_template("/register.html")```

在另一个文件中:

def register(user_name, password, pass_confirm):
    if password != pass_confirm:
        return("Password and password confirmation must match")

1 个答案:

答案 0 :(得分:1)

您使用的函数寄存器没有参数,因此请尝试重命名。

代码将是

@ app.route(“ / register”,methods = [“ POST”,“ GET”])

def reg():

if request.method =="POST":

    if not user_name or not password or not pass_confirm:

return ("all fields are mandatory, also consider to active javaScript for a better expirience",404)

user_name = request.form.get("user_name")

password = request.form.get("password")

pass_confirm = request.form.get("user_name")

register(user_name, password, pass_confirm)

return render_template("/register.html")```

在另一个文件中:


    if password != pass_confirm:

        return("Password and password confirmation must match")```
相关问题