I have this route in application.py for quote:

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

    # if user reached route via POST
    if request.method == "POST":

        # ensure symbol was submitted
        if not request.form.get("symbol"):
            return apology("symbol required")

        # look symbol up on Yahoo Finance and check if it was successful
        stock = lookup(request.form.get("symbol"))
        if not stock:
            apology("symbol is invalid/wasn't found or something else went wrong")

        return render_template("quoted.html", stock=stock)

    elif request.method == "GET":
        return render_template("quote.html")

And these are my templates; quote.html:

{ % extends "layout.html" % }

{ % block title % }
{ % endblock % }

{ % block main % }
    <form action="{{ url_for('quote') }}" method="post">
            <div class="form-group">
                <input autocomplete="off" autofocus class="form-control" name="symbol" placeholder="Enter Stock Symbol" type="text" required/>
            <div class="form-group">
                <button class="btn btn-default" type="submit">Get Quote</button>
{ % endblock % }


{ % extends "layout.html" % }

{ % block title % }
{ % endblock % }

{ % block main % }
        A share of {{ quote }} ({{ symbol }}) is ${{ price }}.
{ % endblock % }

So how do I extract the values in the stock dict in that quoted.html template?

I'm also talking to someone on Facebook Messenger about this, so I'll have to mark it as "solved" (again) if I get it figured out. But I'm still leaving this here just in case. [sorry about doing this again.]


Jinja Documentation | Variables

You can access the values the same way as in Python:

{{ dictionary['key'] }}

You can alternatively use dot notation:

{{ dictionary.key }}
  • I figured that out later. I need to figure out what I'm doing wrong with a certain query I'm trying to execute for buy now. Should I make a new thread for it? My buy route has been pasted here: pastebin.com/yT1TKV0s. I tried to "buy" 2 shares of Netflix's shares and I got the error: "RuntimeError: (sqlite3.OperationalError) near "WHERE": syntax error [SQL: 'UPDATE users SET cash WHERE id=1 AND cash=9718.22']". What am I doing wrong? The error is for line 29 in the code. – Osman Zakir Mar 11 '17 at 23:14
  • This is a syntax error. The format of an UPDATE statement is "UPDATE table_name SET cell=value WHERE field=field". You would need to enter something like 'UPDATE users SET cash=9718.22 WHERE id=1'. – Steve Bunting Mar 12 '17 at 14:30

You must log in to answer this question.

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