0

I'm struggling with register function in application.py since I am having error messages in check50

That says:

:) register page has all required elements
:( registering user succeeds
    expected status code 200, but got 403
:( registration with an empty field fails
    expected status code 400, but got 403
:( registration with password mismatch fails
    expected status code 400, but got 403
:( registration rejects duplicate username
    expected status code 200, but got 403

Also according to log, INFO: "GET / HTTP/1.0" 302 - WARNING: Exception raised while handling cache file Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/cachelib/file.py", line 219, in delete os.remove(self._get_filename(key)) FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmps75vz6j3/dede94cc102d9176064d48a38eb32b3' Here is my code below. Please let me know if you have an idea for why this is wrong. I searched but couldn't find something wrong. Maybe I don't write about those???

@app.route("/register", methods=["GET", "POST"])
def register():
    if request.method == "POST":
        result_checks = is_provided("username") or is_provided("password") or is_provided("confirmation")
        if result_checks != None:
            return result_checks
        if request.form.get("password") != request.form.get("confirmation"):
            return apology("passwords must match")
        try:
            prim_key = db.execute("INSERT INTO users (username, hash) VALUES (:usernane, :hash)",
                    username=request.form.get("username"),
                    hash=generate_password_hash(request.form.get("password")))
        except:
            return apology("username already exists", 403)
        if prim_key is None:
            return apology("registration error", 403)
        session["user_id"] = prim_key
        return redirect("/")

    else:
        return render_template("register.html")

I tried but have no idea. Please help me guys :")

PS. Is there a possibility that something's wrong in html? Here is my register.html

{% extends "layout.html" %}

{% block title %}
    Register
{% endblock %}

{% block main %}
    <form action="/register" method="post">
        <div class="form-group">
            <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text">
        </div>
        <div class="form-group">
            <input class="form-control" name="password" placeholder="Password" type="password">
        </div>
        <div class="form-group">
            <input class="form-control" name="confirmation" placeholder="Password Again" type="password">
        </div>
        <button class="btn btn-primary" type="submit">Register</button>
    </form>
{% endblock %}

You must log in to answer this question.

Browse other questions tagged .