0

So I did pset7 when there was no check50 for this problem, and I decided to try again to check that my solution fits the specifications, almost all the new problems that I found resolved them by myself, however I can not find a solution for the next error that launches check50. The problem seems to be in quote, according to the specifications:

quote Complete the implementation of quote in such a way that it allows a user to look up a stock’s current price.

Require that a user input a stock’s symbol, implemented as a text field whose name is symbol.

Submit the user’s input via POST to /quote.

Odds are you’ll want to create two new templates (e.g., quote.html and quoted.html). When a user visits /quote via GET, render one of those templates, inside of which should be an HTML form that submits to /quote via POST. In response to a POST, quote can render that second template, embedding within it one or more values from lookup.

So I have two templates, quote and quoted. In the first there is only one field to look for a symbol, the second has the following code:

{% extends "layout.html" %}

{% block title %}
    STOCK
{% endblock %}

{% block main %}

    <p>A share of {{stock["name"]}} ({{stock["symbol"]}}) costs {{stock["price"]}}.</p>

{% endblock %}

The quote code is:

@app.route("/quote", methods=["GET", "POST"])
@login_required
def quote():
    """Get stock quote."""
    if request.method == "POST":
        if request.form["symbol"] == "":
            return apology("You must provide a symbol")
        result = lookup(request.form["symbol"])
        if not result:
            return apology("Sorry symbol not exist")
        else:
            return render_template("quoted.html", stock = result)
    elif request.method == "GET":
        return render_template("quote.html")

So what we see on the page is (totally similar to what the implementation of the staff shows):

A share of NL Industries Inc. (NL) costs 5.3.

The question is that check50 throws me the following error:

:( quote handles valid ticker symbol
expected to find "28.00" in page, but it wasn't found 

Log 
sending POST request to /login 
sending POST request to /quote 
checking that status code 200 is returned... 
checking that "28.00" is in page 

It seems to me that the value of the stock appears on the page, so I do not understand what the problem is. Should we use a certain format ?. The specifications do not seem to say anything about it. Check50 is looking in another page ?. I would appreciate a response from someone who encountered this problem.

2 Answers 2

2

I found the solution (this cost me a little). Indeed, the problem was in the formatting of the price output. It is necessary to achieve the exact exit to the expected one to check50 (it would not be bad that it was warned of these peculiarities), the code that had to change between other things was:

price=format(result["price"],'.2f'))
1

Use usd function defined in helpers.py

symbol = request.form.get('symbol')
shares = lookup(symbol)
shares['price'] = usd(shares['price'])

this will solve the problem

You must log in to answer this question.

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