1
00:00:05,210 --> 00:00:09,590
Welcome back, everyone, to this lecture, we're going to give you an overview of some of the jingo

2
00:00:09,590 --> 00:00:14,690
theory behind connecting a view and a URL before we actually start cutting it out in the next lecture.

3
00:00:16,110 --> 00:00:22,650
So as a refresher in jingo views essentially dictate what information is being shown to the client,

4
00:00:23,070 --> 00:00:27,360
you URLs dictate where that information is shown on the actual website.

5
00:00:27,750 --> 00:00:32,880
And these work in concert, so you can essentially think of each of you and you are appearing as a specific

6
00:00:32,880 --> 00:00:34,290
web page on the website.

7
00:00:34,680 --> 00:00:40,170
So very simply, you can just think of a view as a particular web page on your overall website.

8
00:00:40,500 --> 00:00:42,560
But keep in mind, the view can't do it alone.

9
00:00:42,570 --> 00:00:44,880
It needs to be routed through a URL.

10
00:00:47,080 --> 00:00:51,490
You should also keep in mind that not every permutation of a Web page can be known in advance.

11
00:00:51,700 --> 00:00:56,170
For example, how many total blog posts will a website blog eventually have?

12
00:00:56,200 --> 00:00:57,970
You couldn't really know that ahead of time.

13
00:00:58,390 --> 00:01:04,330
So luckily, jingo views and URLs actually support a lot of dynamic and logic features to help with

14
00:01:04,330 --> 00:01:05,349
this sort of task.

15
00:01:05,470 --> 00:01:11,110
For example, instead of having to hard code in an extension on your domain like blog, one block to

16
00:01:11,110 --> 00:01:12,580
block three and so on.

17
00:01:12,910 --> 00:01:15,670
You could have it be dynamic, so it should be blog RN.

18
00:01:15,900 --> 00:01:21,130
And then every time a new template gets added, then you're going to automatically be able to route

19
00:01:21,130 --> 00:01:23,380
that user to the correct blog post.

20
00:01:23,380 --> 00:01:28,150
And it can be dynamic in the sense that if a blog post hasn't been created yet, you send them to a

21
00:01:28,150 --> 00:01:29,220
404 page.

22
00:01:29,230 --> 00:01:30,820
So we'll be learning about that later on.

23
00:01:32,240 --> 00:01:39,560
Now, recall that we have essentially two main URLs that PY files and one is a URL configuration at

24
00:01:39,560 --> 00:01:42,610
a project level, and then the other one is going to be at the app level.

25
00:01:42,620 --> 00:01:46,940
And keep in mind, you can have multiple apps with multiple URLs that pays for each app.

26
00:01:47,450 --> 00:01:54,230
Well, we end up doing is we connect that view through the URL in the app level all the way to the URL

27
00:01:54,230 --> 00:02:00,080
and the project level through the use of path and include Django functions and a list of the view routes

28
00:02:00,080 --> 00:02:04,820
is defined in a list variable called URL patterns, which we've already seen a little bit of.

29
00:02:06,750 --> 00:02:12,600
So recall, previously we ended the last section by creating a view, connecting it to a URL route within

30
00:02:12,600 --> 00:02:17,310
the application and then connecting that URL to the project level URLs that file.

31
00:02:17,610 --> 00:02:22,050
And we're really going to focus on this particular dynamic for the rest of this section, and we'll

32
00:02:22,050 --> 00:02:23,730
get into more and more complex.

33
00:02:23,730 --> 00:02:29,550
These functionalities feature sets for what you can actually do with these URL routes and their particular

34
00:02:29,550 --> 00:02:30,030
views.

35
00:02:31,510 --> 00:02:36,970
Now, when we actually connect a view to our U you l, we do it with a path function call, and the

36
00:02:36,970 --> 00:02:40,600
first argument that's required any path function call is the actual route.

37
00:02:40,960 --> 00:02:43,660
That's going to be the string code that contains the URL pattern.

38
00:02:44,050 --> 00:02:50,230
And what ends up happening is Django actually scans the relevant URL patterns list until it finds a

39
00:02:50,230 --> 00:02:53,620
matching string route, for example, app forward slash.

40
00:02:53,770 --> 00:02:55,290
And keep in mind, later on, we'll see.

41
00:02:55,480 --> 00:03:01,180
We can actually make these sort of routes dynamic to take in an integer that we don't actually know

42
00:03:01,180 --> 00:03:01,770
ahead of time.

43
00:03:03,590 --> 00:03:09,230
Then we have the second required argument underneath the path function, which is the actual view.

44
00:03:09,680 --> 00:03:14,840
So once the matching route is found, the view argument connects to a function or view.

45
00:03:15,080 --> 00:03:18,320
Typically, the find the views that profile the relevant Django app.

46
00:03:18,710 --> 00:03:23,720
So these are the two main arguments you need to be concerned with whenever you're defining path inside

47
00:03:23,720 --> 00:03:30,950
some URLs that pie file, it's where is the actual route to show either a template or your URL on the

48
00:03:30,950 --> 00:03:31,520
website.

49
00:03:31,970 --> 00:03:33,890
And then what view should I be showing it?

50
00:03:33,920 --> 00:03:38,840
So where is the information going to be shown and then what is the information that's going to be shown?

51
00:03:40,230 --> 00:03:43,720
The other two optional arguments are keyword arguments.

52
00:03:43,740 --> 00:03:48,300
So we'll see that later on, we can actually pass in keyword arguments as a dictionary to the view and

53
00:03:48,300 --> 00:03:49,410
have a lot more flexibility.

54
00:03:49,770 --> 00:03:56,280
And then the fourth optional argument is name and actually allows us to name a URL in order to reference

55
00:03:56,280 --> 00:03:57,690
it elsewhere in Django.

56
00:03:58,080 --> 00:03:59,950
We're going to see when we start introducing templates.

57
00:03:59,970 --> 00:04:05,670
This is a very powerful feature that allows us to simply reference a view and URL route through the

58
00:04:05,670 --> 00:04:07,800
use of a custom defined name.

59
00:04:09,500 --> 00:04:13,490
So coming up next, we're to create some simple views in our app and connect them to our project, your

60
00:04:13,690 --> 00:04:14,180
roots.

61
00:04:14,570 --> 00:04:16,220
Let's go ahead and do that in the next lecture.

