Hot answers tagged

10

I found a solution here. I didn't format the price of stock by usd(). When I changed my code from {{ price }} to {{ price | usd }} in quoted.html, it worked.


3

i figure it out myself by looking at how apologize sends the message to apology form and in my case i have to use render like render("quote.php", ["stock" => $stock]);


1

Since the quote spec calls for an element named "symbol", and this if not request.form.get("stock"): is apparently working, it looks like the element is not named properly in the html. FYI to change "I think" to "I know". ls -al helpers.py (in the finance directory) should return -rw------- 1 ubuntu ubuntu 1748 Apr ...


1

Your issue is that you aren't formatted your numbers such that you are probably displaying 28 instead of 28.00 You are given a this: # Custom filter app.jinja_env.filters["usd"] = usd that can be used as a format in jinja. {{ price | usd }} for example will format the price variable as $28.00 for you. Your fractional problem is because you are not ...


1

Your guess: is that it has something to do with a rounding error as it is looking for a specific number. is probably right. Usually using the 'usd' function in helpers.py will fix that right up. In quote you likely need to format price returned from lookup. The buy problem would likely be coming from index.


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 ...


1

Never mind. I feel like an idiot. I figured out what was wrong and have now fixed it. I was not calling the lookup function properly.


1

Check your quote.html, especially the URL the form submits to. I assume that's a Guttenbug (bug by copy&paste).


1

Unfortunately, the API we are now using doesn't return the name, so you do not have to display the name any longer.


1

The API that is being called doesn't return the name, so for backwards compatibility (for those parts of the code that were written when the Yahoo Finance API was being used), the symbol is put into the name. So what you see is expected.


1

You use a string literal """Get stock quote.""" as a comment. That one, as it's on the same indentation level as the if, breaks the if block, but it's not an else keyword, so when eventually finding that else: on the next line, interpreter does not know which if this should belong to. Move your "comment".


1

In flask, @app.route is a decorator. From the flask View Decorators doc: To use the decorator, apply it as innermost decorator to a view function. When applying further decorators, always remember that the route() decorator is the outermost. So a route decorator cannot be defined inside another. Don't you simply want to return render_template(.... ?


1

Look at the tab when you are entering the stock symbol. Does it say "Register"? Looks like quote.html started with the register.html code. It's still calling the register route on submit.


1

Actually what I did wrong is the php tag at the most top where I should write Thanks everyone.


1

session.clear() clears the session variables, which holds the user id, which makes @login_required think there is not a logged in user. (Notice the comment before session.clear() in the supplied login route!)


1

Jinja Documentation | Variables You can access the values the same way as in Python: {{ dictionary['key'] }} You can alternatively use dot notation: {{ dictionary.key }}


1

The error is telling you that the argument sent to lookup is None type. It expects a string type. Instead of looking "forward" to lookup, you need to look "backwards" to discover why request.form.get("search") is returning a None type. Won't request.form.get("search") return None if you have visted quote with a GET method (as from a link)? Review this ...


1

=> is the notation for a key-value pair in an associative array. Arrays that are indexed by key-value pairs like this (instead of indexed by integers, like arrays in C) are sometimes called "hashes" (because they are data structures analogous to "hash tables" in C), so you may sometimes hear => referred to as a "hash rocket". The render() function ...


1

You can see from helpers.php the conditions under which that particular error will be triggered: if (file_exists("../views/{$view}")) { // extract variables into local scope, tc. // else err else { trigger_error("Invalid view: {$view}", E_USER_ERROR); } }


1

As a general rule, a browser cannot access files outside the document root. This is one of 132,000 articles that Mr. Google supplied when asked. php is not likewise constrained because it runs on the server. So displayquote_form.php needs to be located in the public directory (or perhaps a new directory under public and properly pathed). This is consistent ...


Only top voted, non community-wiki answers of a minimum length are eligible