I recently completed Pset9 (everything seems to be running fine on the local server) and decided to run a check50 before submitting. However, Check50 marked two issues in my register function: "Registering user succeeds" and "Registration rejects duplicate username". For both checks, the log's specification is "exception raised in application: TypeError: 'NoneType' object is not subscriptable". Because it looks like the rest of Check50 depends on these earlier checks, the rest of my code wasn't scored.

Does anyone have any pointers as to what this error means and how/why it is occurring? Thanks in advance!

Register function:

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user"""
if request.method=='POST':
    # has user
    if not request.form.get('username'):
        return apology("Must provide a username.")
    existingUser = db.execute("SELECT username FROM users WHERE username=(:username)", username = request.form.get("username"))

    if existingUser:
        return apology("Username already exists.")

    # has password, confirmation, match
    if not request.form.get("password") or not request.form.get("confirmation"):
        return apology("Must provide password and confirmation.")
    if request.form.get("password") != request.form.get("confirmation"):
        return apology("Confirmation does not match provided password.")
    # hash password, add user
    hashPassword = generate_password_hash(request.form.get("password"))

    newUser = db.execute("INSERT INTO users (username, hash) VALUES (:username, :hash)", username=request.form.get("username"), hash=hashPassword)

    print("This is the session: " + str(session))
    # create session to login, redir to home
    session["user_id"] = newUser
    return redirect("/")

    return render_template("register.html")

Register HTML:

{% extends "layout.html" %}

{% block title %}
    Register User
{% 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 class="form-group">
            <input class="form-control" name="password" placeholder="Password" type="password">
        <div class="form-group">
            <input class="form-control" name="confirmation" placeholder="Retype Password" type="password">
        <button class="btn btn-primary" type="submit">Register</button>
{% endblock %}
  • Your register function works fine. That leads me to believe the issue is in your index function. When you test this and register a new user, does your index page load successfully?
    – curiouskiwi
    Feb 21 at 2:45

You must log in to answer this question.

Browse other questions tagged .