0

My Finance program works, python and javascript both, however, I continue to receive errors when running check50.

This seems to be related to my registration function. After looking at various solutions, working with one very helpful user here, and experimenting on my own, I can not understand why my program may be returning a code 400 instead of 200. Here are my error messages:

:( registering user succeeds
expected status code 200, but got 400
Log
sending POST request to /register
checking that status code 200 is returned...

I'm pretty sure I am not receiving code 400, when I use the program to register I receive a code 500 but the user is still registered, I just receive the following:

raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /

:( /check route confirms whether username is available
application raised an exception (rerun with --log for more details)
Log
sending GET request to /check?username=check50student1
checking that status code 200 is returned...
sending POST request to /register
exception raised in application: TemplateNotFound: /

:( registration rejects duplicate username
application raised an exception (rerun with --log for more details)
Log
sending POST request to /register
exception raised in application: TemplateNotFound: /

And here is my /register function:

@app.route("/register", methods=["GET", "POST"])
def register():
    if request.method == "POST":
        if not request.form.get("username"):
            return apology("Username Missing.")

        elif not request.form.get("password"):
           return apology("Password Missing.")

        elif request.form.get("password") != request.form.get("confirmation"):
           return apology("Sorry, password does not match. Please try Again!")

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

        rows = db.execute("SELECT * FROM users WHERE username = :username", username = request.form.get("username"))

        if rows:
            return apology("username already in use", 400)

        added = db.execute(
           "INSERT INTO users(username,hash)VALUES(:username, :hash)",
           username=request.form.get("username"),hash=hashpass,
        )
        session["user_id"]=added

        return render_template("/")

    else:
        return render_template("register.html")

This seems to be my issue,

raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /

however, my templates are all in working order. The template is located when using /login, so I'm not sure where the problem could be. I believe it might have something to do with my session["user_id"].

1

I suspect error message is coming from this line return render_template("/"). There is no templated named "/". In an earlier version of the code the line was return redirect("/"), which is likely what you intended.

1
  • You're getting to know my code better than I am. Thanks again, man. – KullideDev Jan 29 '20 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .