0

When I enter a symbol (stockticker) on my quote page, when I click "submit" the website redirects me to a register page error (403: Must Provide Username)

Why would this happen? I don't even see any mention of /register on my implementation of /quote.

@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
    """Get stock quote."""

if request.method == "POST":
# Ensure a stock ticker was submitted
    if not request.form.get("symbol"):
        return apology("must provide ticker", 403)

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("quote.html")

Here's my implementation of /register if that helps.

@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user"""

# User reached route via POST (as by submitting a form via POST)
if request.method == "POST":

    # Ensure username was submitted
    if not request.form.get("username"):
        return apology("must provide username", 403)

    # Ensure password was submitted
    elif not request.form.get("password"):
        return apology("must provide password", 403)

    # Ensure confirmation was submitted
    elif not request.form.get("confirmation"):
        return apology("must provide confirmation", 403)

    # Ensure password and confirmation match
    elif not request.form.get("password") == request.form.get("confirmation"):
        return apology("Passwords do not match!", 403)

    # Encrypt password
    hash = generate_password_hash(request.form.get("password"), method='pbkdf2:sha256', salt_length=8)

    # Inserts username and password into database. value of result will be the users user_id
    result = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash=hash)
    if not result:
        return apology("Username already exists")

    # Log the user in
    session["user_id"] = result

    # Redirect user to home page
    return redirect("/")

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("register.html")

1 Answer 1

2

Check your quote.html, especially the URL the form submits to. I assume that's a Guttenbug (bug by copy&paste).

3
  • I'm an absolute moron.
    – user21490
    May 8, 2018 at 16:26
  • You're in good company.
    – Blauelf
    May 8, 2018 at 16:29
  • OMG it happens to me too :")
    – Htet Myat
    Aug 12 at 11:28

You must log in to answer this question.