I'm really at a loss after trying to get Quote to work for the past two days.

I'm able to get the quote.html page to seemingly work but the json query and transfer to quoted.html returns a 500 "Internal Server Error."

I've looked at every solution I can find online and tried to plug components into my code to reverse engineer what I'm doing wrong but I can't get anything to work.

Any pointers on what I've got wrong and what direction to head in would be appreciated.

(Starting with a screenshot because I can't get the flask/Python and HTML/jinja to format in the same code blocks.)

enter image description here


INFO:werkzeug: - - [21/Oct/2018 02:21:51] "GET /static/styles.css HTTP/1.1" 200 -
INFO:werkzeug: - - [21/Oct/2018 02:21:53] "GET /quote HTTP/1.1" 200 -
INFO:werkzeug: - - [21/Oct/2018 02:21:53] "GET /static/styles.css HTTP/1.1" 200 -
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.iextrading.com:443
DEBUG:urllib3.connectionpool:https://api.iextrading.com:443 "GET /1.0/stock/AAPL/quote HTTP/1.1" 200 None
ERROR:flask.app:Exception on /quote [POST]
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/workspace/pset7/finance/helpers.py", line 33, in decorated_function
    return f(*args, **kwargs)
  File "/home/ubuntu/workspace/pset7/finance/application.py", line 166, in quote
    return render_template("/quoted", stock=stock)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/templating.py", line 134, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/jinja2/environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/templating.py", line 58, in get_source
    return self._get_source_fast(environment, template)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/templating.py", line 86, in _get_source_fast
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /quoted
INFO:werkzeug: - - [21/Oct/2018 02:21:57] "POST /quote HTTP/1.1" 500 -
ERROR:werkzeug:Error on request:
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/serving.py", line 270, in run_wsgi
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/serving.py", line 258, in execute
    application_iter = app(environ, start_response)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1748, in handle_exception
    return self.finalize_request(handler(e), from_error_handler=True)
  File "/home/ubuntu/workspace/pset7/finance/application.py", line 198, in errorhandler
    return apology(e.name, e.code)
AttributeError: 'TemplateNotFound' object has no attribute 'code'

from application.py

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

    if request.method == "POST":

        if not request.form.get("symbol"):
            return apology("Must supply a stock symbol", 403)

    #     # stock = lookup(request.form.get("Symbol"))["name"])
    #     # stock = lookup(request.form.get("symbol")["name"])
        s = request.form.get("symbol")
        stock = lookup(s)

        return render_template("/quoted", stock=stock)
    #     # return render_template("quoted.html", stock=stock)
        # return redirect("/")

    # # User reached route via GET (as by clicking a link or via redirect)
        return render_template("quote.html")

def quoted():
    """render stock price"""

    return render_template("/quoted", stock=stock) 


{% extends "layout.html" %}

{% block title %}
    Log In
{% endblock %}

{% block main %}

    <form action="/quote" method="post">
        <div class="form-group">
            <input autofocus class="form-control" name="symbol" placeholder="Stock Symbol" type="text"/>
        <button class="btn btn-primary" type="submit">Look-up!</button>
{% endblock %}


{% extends "layout.html" %}

{% block title %}
{% endblock %}

{% block main %}
    <!--{{ symbol[0] }}-->
    {{ stock['name'] }} ({{ stock['symbol'] }}): {{ symbol[price] }}
{% endblock %}

1 Answer 1


When looking at the log file, we can see that the last line says:

  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/templating.py", line 86, in _get_source_fast
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /quoted

But your template is called quoted.html (which is correct), rather than /quoted.

Let's look again in the log, and find the last line that was written by you:

  File "/home/ubuntu/workspace/pset7/finance/application.py", line 166, in quote
    return render_template("/quoted", stock=stock)

So your code tries to call the quoted.html template with 1 argument (stock).

But I can see that your template quoted.html uses more than one argument ...

Finally, to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thanks so much for your help, Peter.
    – Scott
    Oct 22, 2018 at 6:03

You must log in to answer this question.

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