When I launch my web server and test "quote" I get an AssertionError after I search for the symbol. No matter what I change or tweak the error is OMNISCIENT. No kidding. The error states:
"AssertionError: A setup function was called after the first request was handled. This usually indicates a bug in the application where a module was not imported and decorators or other functionality was called too late. To fix this make sure to import all your view modules, database models and everything related at a central place before the application starts serving requests."
My code for quote is:
@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
if request.method == "POST":
if not request.form.get("symbol"):
return apology("Must enter stock symbol")
symbols = request.form.get("symbol")
if not lookup(symbols):
return apology("Stock doesn't exist")
stock = lookup(symbols)
name = stock["name"]
price = stock["price"]
symbol = stock["symbol"]
@app.route("/stock")
def stock():
return render_template("stock.html", name = name, price = price, symbol = symbol)
else:
return render_template("quote.html")
It's very confusing because the information provided by the error message doesn't do much to direct me. However the traceback or most recent call, to the program was given as:
@app.route("/stock")
The two templates I'm using are stock.html and quote.html, quote is to get the symbol and stock is to display the information. Quote is:
{% extends "layout.html" %}
{% block title %}
Quote
{% endblock %}
{% block main %}
<form action="{{ url_for('quote') }}" method="post">
<fieldset>
<div class="form-group">
<input class="form-control" name="symbol" placeholder="Symbol" type="text"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Search</button>
</div>
</fieldset>
</form>
{% endblock %}
And the code for stock is:
{% extends "layout.html" %}
{% block title %}
Stock
{% endblock %}
{% block main %}
<form action="{{ url_for('stocks') }}" method="post">
<p>
Name: {{name}}
Price: {{price}}
Symbol: {{symbol}}
</p>
</form>
{% endblock %}
If anyone could look into (and hopefully help me solve) my problem that would be fantastic. Thanks!