1 00:00:00,000 --> 00:00:00,670 2 00:00:00,670 --> 00:00:03,490 Now, let's allow users to look up information for stocks 3 00:00:03,490 --> 00:00:04,980 that they're interested in. 4 00:00:04,980 --> 00:00:07,060 For quote, you have three tasks. 5 00:00:07,060 --> 00:00:12,100 One is to display a form where the users can inquire after this information. 6 00:00:12,100 --> 00:00:14,560 Second, you want to retrieve that information, 7 00:00:14,560 --> 00:00:18,200 the stock quote, and then display it back to the user. 8 00:00:18,200 --> 00:00:22,390 So let's start by displaying a form to the user where they can look up 9 00:00:22,390 --> 00:00:24,550 information about these stocks. 10 00:00:24,550 --> 00:00:28,690 For this, let's create a new template, quote.html. 11 00:00:28,690 --> 00:00:30,910 We'll want to write a form for the stock look up, 12 00:00:30,910 --> 00:00:34,000 where the form input is the symbol for the stock 13 00:00:34,000 --> 00:00:36,160 that the user wants to look up. 14 00:00:36,160 --> 00:00:39,610 Now that that user has given us a symbol, let's take that symbol 15 00:00:39,610 --> 00:00:42,800 and retrieve the relevant information. 16 00:00:42,800 --> 00:00:46,180 The lookup function uses an API to retrieve information 17 00:00:46,180 --> 00:00:48,980 about a stock given a symbol. 18 00:00:48,980 --> 00:00:51,880 It will return a dict, the name of that stock, 19 00:00:51,880 --> 00:00:55,450 the current price, and the symbol of that given stock. 20 00:00:55,450 --> 00:00:59,380 Now that we have this information let's relay it to the user. 21 00:00:59,380 --> 00:01:03,220 We'll want to display this stock information in another template. 22 00:01:03,220 --> 00:01:05,269 Why are we creating a new template? 23 00:01:05,269 --> 00:01:10,150 Well, it's because the quote.html template already has a form. 24 00:01:10,150 --> 00:01:13,780 This is going to look different, so we'll create a new template. 25 00:01:13,780 --> 00:01:16,660 Now, we only want to display this new template, 26 00:01:16,660 --> 00:01:20,060 if the stock symbol that the user provided is valid. 27 00:01:20,060 --> 00:01:23,560 Otherwise, we'll apologize again. 28 00:01:23,560 --> 00:01:26,260 Now, this stock information is in Python, 29 00:01:26,260 --> 00:01:29,260 but we're displaying information in HTML. 30 00:01:29,260 --> 00:01:32,410 So how do we communicate between these two files? 31 00:01:32,410 --> 00:01:36,430 Well, let's take a look at render_template. 32 00:01:36,430 --> 00:01:41,350 Render_template allows us to pass in values from Python to HTML. 33 00:01:41,350 --> 00:01:45,370 Let's say I have a template called hello.html. 34 00:01:45,370 --> 00:01:47,010 Let's go to the main block. 35 00:01:47,010 --> 00:01:50,350 Here, you'll see that I have HTML paragraph tags. 36 00:01:50,350 --> 00:01:53,200 Within it, I say, Hello comma. 37 00:01:53,200 --> 00:01:56,530 And, then, I have a placeholder for a Python variable 38 00:01:56,530 --> 00:01:59,360 enclosed into curly braces. 39 00:01:59,360 --> 00:02:04,420 So, then, within application.py when I'm defining my route for hello, 40 00:02:04,420 --> 00:02:08,380 I'm going to call render_template, passing in the name for the template 41 00:02:08,380 --> 00:02:13,520 that I'm rendering, as well as, the value for the variable name. 42 00:02:13,520 --> 00:02:15,880 So what would the HTML look like? 43 00:02:15,880 --> 00:02:21,180 If I passed in world, then I'd be able to say, hello, world! 44 00:02:21,180 --> 00:02:22,337