1
00:00:05,860 --> 00:00:10,160
Welcome back in this lecture we're going to discuss basic routing in our web applications.

2
00:00:11,590 --> 00:00:14,840
We just saw how to create a web application with a single page.

3
00:00:14,860 --> 00:00:18,730
In this case it was returned in the form of a string with a single header line.

4
00:00:18,730 --> 00:00:25,290
Now let's see how we can add a multiple routes that is to say multiple pages on our web application.

5
00:00:25,320 --> 00:00:31,740
The key to this is in the decorator app route the string parameter that we pass into that decorator

6
00:00:31,800 --> 00:00:35,120
determines the Yoro extension that will link to the function.

7
00:00:35,160 --> 00:00:44,490
Otherwise known as a view currently our home page or domain is locally represented as 1 2 7 0 0 1 colon

8
00:00:44,570 --> 00:00:49,700
and then 5000 where that 5000 number may change depending on what ports are available on your local

9
00:00:49,700 --> 00:00:50,900
machine.

10
00:00:50,900 --> 00:00:53,870
What we do is we use decorators to add onto this.

11
00:00:53,870 --> 00:01:00,200
So we say at apt that route and then as a string we pass in whatever your L extension we want to K'NEX

12
00:01:00,290 --> 00:01:01,680
offer this domain name.

13
00:01:01,700 --> 00:01:07,970
So for example if I decorated a view function with forward slash some underscore page then I would be

14
00:01:07,970 --> 00:01:11,130
able to visit in my browser our domain name.

15
00:01:11,180 --> 00:01:17,180
In this case the local Yoro slash some page and actually see the view represented there once a page

16
00:01:17,180 --> 00:01:23,660
is actually deployed the web that local 1 to 7.0 points or 0.1 that's going to be replaced by your actual

17
00:01:23,660 --> 00:01:26,510
domain name whatever domain you happen to purchase online.

18
00:01:26,540 --> 00:01:31,820
You can say something like site dot com forward slash and then some page or whatever other pages you

19
00:01:31,820 --> 00:01:33,610
have on your web application.

20
00:01:33,620 --> 00:01:38,690
The main idea here is that we're just passing in a string to connect that view function to an actual

21
00:01:38,690 --> 00:01:41,020
routing in your application.

22
00:01:41,700 --> 00:01:46,290
Let's create an example of this by going to the actual text editor and showing you how it works.

23
00:01:46,310 --> 00:01:46,580
All right.

24
00:01:46,590 --> 00:01:51,360
Here we have the application we were working on last time fact I'm going to just expand it here and

25
00:01:51,360 --> 00:01:56,370
I have from flask import flask and right now I just have one view function called index which stands

26
00:01:56,370 --> 00:02:01,680
for my index page and notice how its route is just a single forward slash indicating that this is just

27
00:02:01,680 --> 00:02:08,900
going to go to one to seven point zero point zero point one colon 5000.

28
00:02:08,910 --> 00:02:12,150
Let's imagine that I want another page in my web application.

29
00:02:12,300 --> 00:02:17,520
Let's create a page and we're going to call the View function for info.

30
00:02:17,700 --> 00:02:20,090
Technically you can call this function whatever you want.

31
00:02:20,310 --> 00:02:22,860
And this one is going to return in other.

32
00:02:22,870 --> 00:02:29,970
Will say something like just some information about puppies let's say Puppies are cute and we'll close

33
00:02:29,970 --> 00:02:31,430
that heading one tag.

34
00:02:32,010 --> 00:02:35,960
Then all we need to do is call app route.

35
00:02:35,980 --> 00:02:41,590
So that's a decorator forward slash and then whatever extension you want here.

36
00:02:41,680 --> 00:02:50,450
So for instance we can say information and now when I visit my page to seven point zero point 0.1 colon

37
00:02:50,760 --> 00:02:56,730
5000 forward slash information or whatever the string code is here.

38
00:02:56,930 --> 00:03:00,320
I'm going to call this view function in which case I should see.

39
00:03:00,320 --> 00:03:01,320
Puppies are cute.

40
00:03:01,610 --> 00:03:04,760
So let's make sure we save this and let's run our file now.

41
00:03:04,780 --> 00:03:09,370
I'll say Python basic but pie or whatever you happen to call this file Mikuru don't call it Flast that

42
00:03:09,400 --> 00:03:11,620
pi and enter here.

43
00:03:11,660 --> 00:03:12,560
Notice it's running.

44
00:03:12,620 --> 00:03:15,830
So let's check it out in our browser and to bring in my browser.

45
00:03:16,130 --> 00:03:17,450
It says Hello puppy.

46
00:03:17,480 --> 00:03:18,220
I refresh this.

47
00:03:18,230 --> 00:03:19,700
It still says hello puppy.

48
00:03:19,700 --> 00:03:27,050
Now I'm going to ask for forward slash information to enter and now says puppies are cute.

49
00:03:27,290 --> 00:03:30,070
So what it did is using that route decorator.

50
00:03:30,230 --> 00:03:35,270
It said OK call the view function info since that's the function that's being decorated and then return

51
00:03:35,270 --> 00:03:36,570
back whatever it says there.

52
00:03:36,590 --> 00:03:38,480
In this case those puppies are cute.

53
00:03:38,660 --> 00:03:41,120
If you end up trying to visit a route that's not the fine.

54
00:03:41,150 --> 00:03:44,540
For example say slash not the find you enter.

55
00:03:44,600 --> 00:03:46,010
It's going to get not found.

56
00:03:46,040 --> 00:03:51,260
Essentially this is a forum for saying the requests you're L was not found on the server which means

57
00:03:51,320 --> 00:03:54,600
this hasn't been defined within your actual flask application.

58
00:03:54,890 --> 00:03:56,560
OK so just a quick review.

59
00:03:56,570 --> 00:04:01,840
All you're doing here is passing forward slash and then the string code you want for your actual routing.

60
00:04:02,150 --> 00:04:06,090
Let's go ahead and go to the next lecture where we're going to discuss dynamic routing.

61
00:04:06,230 --> 00:04:11,600
That is to say this information is actually dynamic depending on what information is passed the page

62
00:04:11,960 --> 00:04:14,020
we're going to discuss that in the next lecture.

63
00:04:14,030 --> 00:04:14,640
We'll see you there.
