I am implementing a quote function in application.py. But the result is ridiculous. After I enter a symbol to search for, I get an apology.html(saying Missing Username!), but this apology.html with this message I have to receive only while registering and not entering Username.
Why do I get this .html after executing quote function?? What is the problem?
Thanks ;)
Here is my implementation of quote:
@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
"""Get stock quote."""
if request.method == "POST":
quote = lookup(request.form.get("symbol"))
if quote == None:
return apology("Invalid symbol")
return render_template("quote_response.html", name = quote["name"], symbol = quote["symbol"], quote = quote["price"])
else:
return render_template("quote.html")
Here is register function (seems to work correctly)
@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user.*"""
# forget any user_id
#session.clear()
if request.method == "POST":
if not request.form.get("username"):
return apology("Missing Username!")
elif not request.form.get("password"):
return apology("Missing password!")
if request.form.get("password") != request.form.get("password_confirm"):
return apology ("Passwords do not match!")
# hash the password
encrypted = pwd_context.encrypt(request.form.get("password"))
# username must be uniq
result = db.execute("INSERT INTO users (username, hash) VALUES (:username, :password)",
username = request.form.get("username"), password = encrypted)
if not result:
return apology("Username is already exists")
# store id in session
rows = db.execute("SELECT * FROM users WHERE username = :username", username=request.form.get("username"))
session["user_id"] = rows[0]["id"]
# redirect user to home page
return redirect(url_for("index"))
else:
return render_template("register.html")
My quote.html
{% extends "layout.html" %}
{% block title %}
Register
{% endblock %}
{% block main %}
<form action="{{ url_for('register') }}" method="post">
<fieldset>
<div class="form-group">
<input autocomplete="off" autofocus class="form-control" name="symbol" placeholder="Symbol" type="text"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Quote</button>
</div>
</fieldset>
</form>
{% endblock %}