1
00:00:05,340 --> 00:00:06,180
Welcome back.

2
00:00:06,180 --> 00:00:11,220
We just saw how we can use basic routes in order to direct our user to a different page and our web

3
00:00:11,250 --> 00:00:12,170
application.

4
00:00:12,420 --> 00:00:17,220
Now let's talk about dynamic routes which will be different routes depending on the situation.

5
00:00:18,070 --> 00:00:23,490
So often we're going to want your extensions to be dynamic based on that particular situation.

6
00:00:23,500 --> 00:00:28,840
A good example of this is maybe you have a web application with many users and each of those users has

7
00:00:28,840 --> 00:00:30,020
a profile page.

8
00:00:30,090 --> 00:00:35,290
So you're going to want the profile page Yorkhill for each particular user to be unique that we don't

9
00:00:35,290 --> 00:00:39,260
have collisions based off of two users having the same your l.

10
00:00:39,280 --> 00:00:44,140
So that's usually going to be in the form of something like your domain name or site name dot com slash

11
00:00:44,140 --> 00:00:50,740
user slash and then that unique user name or that unique profile name to achieve this effect.

12
00:00:50,780 --> 00:00:54,530
We can use dynamic routes and dynamic routes have two key aspects.

13
00:00:54,530 --> 00:01:00,560
One is that the variable inside that route decorator that is the at app dot route decorator it's going

14
00:01:00,560 --> 00:01:05,540
to have a variable that's going to be passed in and then that's going to sync with the parameter that's

15
00:01:05,540 --> 00:01:08,910
passed into the function that the decorator is decorating.

16
00:01:08,930 --> 00:01:11,320
So let's see what this actually looks like.

17
00:01:12,020 --> 00:01:14,520
So here we have an example of a dynamic route.

18
00:01:14,660 --> 00:01:19,520
So we have our decorators saying at apt that route and there were directing them to some page slash

19
00:01:19,820 --> 00:01:24,230
and then you notice we have a dynamic aspect of this which is that name variable.

20
00:01:24,230 --> 00:01:27,230
And then we're going to be able to pass that into our function.

21
00:01:27,230 --> 00:01:29,530
So we have a function other page name.

22
00:01:29,690 --> 00:01:34,760
And in this case we're just returning user and there were formatting that name into that user.

23
00:01:34,760 --> 00:01:40,250
So when someone visits that page we're essentially going to say go to some page forward slash and then

24
00:01:40,250 --> 00:01:45,260
you're going to be able to type in whatever profile name you want and the page is going to respond back

25
00:01:45,560 --> 00:01:50,300
with user colon and then that profile name later on we're going to see how to use this parameter with

26
00:01:50,300 --> 00:01:53,530
templates and actually passing in a request contex.

27
00:01:53,540 --> 00:01:56,960
But right now this is going to be a very simple example of dynamic routing.

28
00:01:56,960 --> 00:01:59,820
Main idea is to get here before we head over to the text editor.

29
00:01:59,990 --> 00:02:05,840
It's just that you'll be able to pass in this variable into the function and then use it somehow.

30
00:02:05,840 --> 00:02:08,240
Let's go to the text editor and show this in action.

31
00:02:08,290 --> 00:02:08,540
All right.

32
00:02:08,530 --> 00:02:10,200
Here we are at the text editor.

33
00:02:10,250 --> 00:02:13,310
We've created our basic routing for the index or home page.

34
00:02:13,370 --> 00:02:16,830
And then we have this other basic route for the information page.

35
00:02:16,880 --> 00:02:20,230
Let's show you how we can create a dynamic row.

36
00:02:20,270 --> 00:02:21,420
We'll start off by saying.

37
00:02:21,650 --> 00:02:25,650
App dot routes or route.

38
00:02:25,990 --> 00:02:27,650
And then we're going to save forward slash.

39
00:02:27,670 --> 00:02:30,490
In this case is going to be puppy profiles.

40
00:02:30,700 --> 00:02:37,180
So it's a puppy forward slash and then each puppy can have a name and where we're going to do is when

41
00:02:37,180 --> 00:02:43,420
you visit the page puppy slash and that particular puppy's name the actual page is going to report back

42
00:02:43,480 --> 00:02:44,400
that puppy's name.

43
00:02:45,720 --> 00:02:48,430
And we'll call this view puppy.

44
00:02:48,680 --> 00:02:51,850
It takes in that name variable that was supplied in the euro.

45
00:02:52,220 --> 00:03:01,350
And then it's just going to return a head or one that says this is page 4 and they're going to use print

46
00:03:01,350 --> 00:03:04,150
formatting in order to format this.

47
00:03:04,300 --> 00:03:12,580
So also close off the H1 tag and they will say that format the name.

48
00:03:12,680 --> 00:03:21,070
All right let's save this and then let's start our application basic PI enter and then let's bring up

49
00:03:21,160 --> 00:03:22,220
our browser.

50
00:03:22,220 --> 00:03:22,520
All right.

51
00:03:22,520 --> 00:03:23,710
I've brought in my browser.

52
00:03:23,710 --> 00:03:26,280
Keep in mind I'm very zoomed in right now.

53
00:03:26,350 --> 00:03:32,130
I'm going to go forward slash and go to the information page and it says Puppies are cute.

54
00:03:32,140 --> 00:03:36,090
Now let's try to use that dynamic view which was puppy.

55
00:03:36,370 --> 00:03:39,290
And then we did slash and then some name.

56
00:03:39,520 --> 00:03:43,740
So I'm going to come here and say puppy forward slash.

57
00:03:43,930 --> 00:03:46,960
And let's just say some underscore name we enter.

58
00:03:47,080 --> 00:03:51,610
You're going to get dynamic result of this is a page for some underscore name.

59
00:03:51,680 --> 00:03:56,470
And what's happening here is we have this dynamic route and we're passing in this variable into our

60
00:03:56,470 --> 00:04:00,400
function which in our case is just a very simple function that returns.

61
00:04:00,400 --> 00:04:04,130
This is a page for and then that variable name that was passed then.

62
00:04:04,180 --> 00:04:06,020
So let's make one for rufous here.

63
00:04:07,410 --> 00:04:11,250
We'll say rufous enter and then this is a page for rufous.

64
00:04:11,250 --> 00:04:15,360
Notice how I would be able to Ansermet function do whatever I want with this string.

65
00:04:15,420 --> 00:04:18,840
I could have made it all lowercase made all uppercase and so on.

66
00:04:18,840 --> 00:04:24,000
So do a quick example of that by making just a page that returns back the name passed in except it's

67
00:04:24,000 --> 00:04:30,520
an all uppercase sort of come back here to our text editor and I'm going to edit this.

68
00:04:30,560 --> 00:04:32,550
Of saying this is a page for that name.

69
00:04:32,580 --> 00:04:33,870
I'm going to say this is

70
00:04:37,060 --> 00:04:44,590
uppercase and then we're going to pass in that same name with print formatting and then call up or on

71
00:04:44,590 --> 00:04:45,300
that name.

72
00:04:45,340 --> 00:04:52,600
So it takes in that string it's going to uppercase it and then say uppercase and then pass that in and

73
00:04:52,600 --> 00:04:53,290
Altes restart.

74
00:04:53,290 --> 00:04:59,430
This will say Python basic but by bringing back my page here this is the old page we're going to refresh

75
00:04:59,440 --> 00:05:00,370
this.

76
00:05:00,370 --> 00:05:03,900
And now we see uppercase and notice how it's in all uppercase rufous.

77
00:05:04,000 --> 00:05:08,170
So no matter what I'm passing in here even if they're all lowercase it's going to uppercase all those

78
00:05:08,170 --> 00:05:09,060
letters.

79
00:05:09,100 --> 00:05:13,510
So this is a very simple example if I can take in the variable that's passed then and then play around

80
00:05:13,510 --> 00:05:15,310
with it inside that function.

81
00:05:15,310 --> 00:05:18,340
Later on we're going to see how we can able to pass that into templates.

82
00:05:18,340 --> 00:05:19,930
And as a context.

83
00:05:19,930 --> 00:05:24,670
And in fact we're going to be able to pasan not just simple strings but things like dictionaries into

84
00:05:24,670 --> 00:05:26,820
our templates and use them there.

85
00:05:26,830 --> 00:05:28,240
All right that's it for this lecture.

86
00:05:28,240 --> 00:05:29,330
We'll see what the next one.
