0

First post here...seems I'm coming unstuck at the pointy end of the course. Hahaha!

My code doesn't seem to be passing Check50 through Quotes/Buy/Sell - although the functionality seems to be fine for me across the board.

I'll just paste my "Quote" code below, as I have a hunch it will be the same issue through all three sections...I originally only had one "quote.html" but added "quotes.html" as it was suggested in the walk through.

Thanks in advance!! :)


@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
    price = 0
    if request.method == "POST":
        if "check" in request.form:
            stock = request.form.get("symbol")
            if stock == "":
                return apology("please enter stock code", 400)

            elif lookup(stock) is None:

                return apology("stock not valid", 400)

            else:
                quotes = lookup(stock)
                name = quotes['name']
                symbol = quotes['symbol']
                price = quotes['price']

                return render_template("quotes.html", name=name, price=price, symbol=symbol)

    else:
        return render_template("quote.html", price=price)

{% extends "layout.html" %}

{% block title %}
    Quote
{% endblock %}

{% block main %}

    Stock Quote
    <br><br>

    <form action="/quote" method="post">
        <input type="text" placeholder="Type Stock Code" name="symbol" id="symbol">
        <button type="submit" placeholder="Check Price" name="check" id="check">Check Price</button>
        <output type="text" name="price" id="price" value="{{ price }}">{{ price | usd}}</output>
        <br><br>
        <output type="text" name="name" id="name" value="{{ name }}">{{ name }}</output>
        <output type="text" name="error" id="error" value="{{ error }}">{{ error }}</output>


    </form>

{% endblock %}

{% extends "layout.html" %}

{% block title %}
    Quote
{% endblock %}

{% block main %}

Stock Quote Below
<br><br>

<form action="/quote" method="post">
    <input type="text" placeholder="Type Stock Code" name="symbol" id="symbol">
    <button type="submit" placeholder="Check Price" name="check" id="check">Check Price</button>
    <output type="text" name="price" id="price" value="{{ price }}">{{ price | usd}}</output>
    <br><br>
    <output type="text" name="name" id="name" value="{{ name }}">{{ name }}</output>
    <output type="text" name="error" id="error" value="{{ error }}">{{ error }}</output>


</form>

{% endblock %}

Check50 Result Check50 Buy Check50 Sell

1 Answer 1

0

TTBOMK: check50 treats the functions as API's. To wit, they are not called through the GUI; it uses curl or a python library or some mechanism to automate it. This line if "check" in request.form: looks to me like the root of the problem. Since checker is not using the GUI, there is no "check", and since there is no else program terminates throwing the error.

2
  • You were spot on! I'd managed to over complicate it when I was combining the quote and buy pages...now it functions more like the staff version, annnd Check50 passed!
    – Jumbot
    Commented Jun 27, 2023 at 9:55
  • Thanks so much! I also didn't realise that hitting return would add my comment automatically....hahaha!
    – Jumbot
    Commented Jun 27, 2023 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .