0

I am new in programming and I know that are useful things out there like wtforms for this, but I want to practice a little before dive into it.

The idea is to create a web app that register the user, and I think it is better to keep this logic apart from the application code.

The problem is that I have this error message: TypeError: register() takes 0 positional arguments but 3 were given I am confused because the function declaration has positional arguments, the code I wrote is:

app code:

@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")```

in another file:

def register(user_name, password, pass_confirm):
    if password != pass_confirm:
        return("Password and password confirmation must match")
4
  • The problem is the other register function doesn't have positional arguments. Maybe rename the one in the other file to register_logic or something. Commented May 17, 2020 at 18:01
  • Python does not support function overloading. Consider giving one of the two functions a different name. Commented May 17, 2020 at 18:02
  • You are calling same function inside 'register' function (recursion). Make sure you are calling correct register, you need to import it if it is from another file. Example: import AnotherFile AnotherFile.register(user_name, password, pass_confirm) Commented May 17, 2020 at 18:04
  • Thank you guys! All relevant points. I changed the called function name. =D tnx a lot! Commented May 20, 2020 at 0:44

1 Answer 1

1

You used the function register with no arguments ,so try to rename it.

the code will be

@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")```

in another file:


    if password != pass_confirm:

        return("Password and password confirmation must match")```
Sign up to request clarification or add additional context in comments.

1 Comment

Ow, I see..I used the same name for both functions. This solved the problem! Thank you! =D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.