WEBVTT

00:01.940 --> 00:02.510
Okay.

00:02.510 --> 00:06.290
Let's talk about URLs in this video.

00:07.310 --> 00:17.960
So inside our project, if we open our project here, we have URLs and that's main URLs that are responsible

00:17.960 --> 00:20.900
for our routing in our application.

00:20.900 --> 00:28.040
So if will open this, I can actually remove all that, but feel free to read this.

00:28.040 --> 00:30.440
That's very useful information here.

00:30.440 --> 00:35.840
What kind of different URLs we might use in our application, but I will remove it from here.

00:36.440 --> 00:44.690
So what's happening here is that we have at the moment one URL, one extra URL, because if we go to

00:44.690 --> 00:54.530
this base URL, I can see here that basic Django site is displayed and it means really nothing because

00:54.530 --> 00:56.870
it's just a placeholder for application.

00:56.870 --> 01:04.700
It's telling us that this is the Django has been successfully installed, but we need to do our own

01:04.700 --> 01:11.050
URLs and if we come back to our application here at the moment we have admin and we already visited

01:11.060 --> 01:12.080
admin here.

01:12.080 --> 01:21.710
So what we can do here and this is on the project level, we can do a reference to another URL file.

01:21.710 --> 01:27.590
So what I will do is I will go to the demo and I will create another URL file.

01:29.470 --> 01:31.540
So new file.

01:31.960 --> 01:35.950
Right click on the folder, new file and then I will do urls.

01:36.260 --> 01:40.540
PY and I have two files.

01:40.630 --> 01:41.230
URLs.

01:41.230 --> 01:51.280
Basically I will close others and I have one file that is for the project which is main file and another

01:51.280 --> 01:52.870
for our application.

01:52.870 --> 02:01.450
What I can do is basically I will copy what I have here and I will paste it for now here and in this

02:01.450 --> 02:03.180
part I can leave it blank.

02:03.190 --> 02:07.680
We don't have anything here for now, but I will add it later on.

02:07.690 --> 02:14.020
So what we can do is we might have some kind of folders in our URL.

02:14.020 --> 02:15.850
So if I will go to.

02:17.720 --> 02:22.390
At the end to slash demo and then slash something.

02:22.400 --> 02:26.690
I will use URL URLs from this application.

02:26.690 --> 02:33.830
So basically on the main project URLs, I will have that reference to demo and that will reference another

02:33.830 --> 02:39.650
file and I will go deeper and deeper and I might have a more than one level.

02:39.650 --> 02:41.480
It's all depend on us.

02:41.480 --> 02:46.490
So basically what we need to do is we need to add extra path here.

02:46.490 --> 02:54.860
I will just duplicate it here and I will do demo and wherever we go to demo we will need to do include.

02:56.710 --> 03:02.230
We need to also import that include from URLs.

03:02.230 --> 03:06.700
So include will give us an option to include some other urls.

03:06.700 --> 03:12.970
So urls is sorry, demo dot URLs.

03:13.300 --> 03:18.910
So basically what we are doing here, if we fill in our URL, we'll have a demo.

03:18.940 --> 03:24.010
We will include the URLs from this file which is inside the demo.

03:24.010 --> 03:26.680
So we might have another level here.

03:27.340 --> 03:31.210
So if I will save it now and then I will.

03:33.960 --> 03:35.460
Refresh it like this.

03:36.970 --> 03:38.450
And if going to be rich.

03:38.470 --> 03:46.990
Probably our server is not working at the moment because we need to include some extra information.

03:46.990 --> 03:51.130
So we need to go here and then we need to do something there.

03:51.130 --> 03:57.580
So basically what we will do, I will finish this exercise first and I will show you how it works later

03:57.580 --> 03:57.970
on.

03:57.970 --> 04:04.480
So what we will need to do is we'll need to have at least one reference so we'll have a path like this,

04:04.480 --> 04:10.690
which is kind of empty path, but that will be on the level demo is already we are in the demo and then

04:10.690 --> 04:15.400
we'll use our views and in views I can open views.

04:17.300 --> 04:19.280
We don't have anything here.

04:19.280 --> 04:22.400
So what we can do is we can create a simple function.

04:22.400 --> 04:27.500
So let's say first function here, and that's our definition first.

04:27.500 --> 04:32.210
And then so request will be part of this.

04:32.240 --> 04:33.620
We're not going to use it here.

04:33.620 --> 04:43.520
We will do return simple Http response and we need to import that.

04:43.550 --> 04:44.810
So from.

04:46.010 --> 04:47.810
Django http.

04:48.950 --> 04:52.760
Import that http response.

04:52.760 --> 04:59.240
And in this http response, what we can do is we can include some something.

04:59.240 --> 05:00.020
So.

05:00.860 --> 05:07.670
First search from views will include that.

05:07.670 --> 05:16.130
And that's a simple function we have in our Python on the views level so that first I can use it here.

05:16.340 --> 05:26.420
So what we need to do first we need to import so from current folder import views and that views are

05:26.420 --> 05:30.710
available here and inside here I can do views.

05:31.730 --> 05:33.170
And I can do.

05:33.210 --> 05:35.360
First I need to call it.

05:35.360 --> 05:39.340
So it is a reference to our view first.

05:39.350 --> 05:46.070
So now I will run the server and we don't have any issues.

05:46.070 --> 05:53.150
Now if we come back here and then I will refresh this changed.

05:53.180 --> 05:59.990
This changed because now we have our URLs in place, so there is no default page displayed with the

05:59.990 --> 06:00.390
Django.

06:00.410 --> 06:08.690
Now we have this demo and this admin, by the way, you see that screen because you have the back through

06:08.720 --> 06:09.830
in the settings file.

06:09.830 --> 06:17.570
So if you will put your application on the server, it will be better to go to the settings.

06:18.510 --> 06:21.350
And the back change it to false here.

06:21.360 --> 06:27.810
So for us to work on the on the testing environment on our machine, we can have it true because it's

06:27.810 --> 06:30.690
actually very, very handy to see that kind of thing.

06:30.690 --> 06:35.940
So basically the URL without anything here is not acceptable anymore.

06:35.940 --> 06:38.700
We need to put it demo or admin.

06:38.700 --> 06:41.820
And that's coming from our file, which is.

06:43.280 --> 06:44.800
This one URL.

06:44.810 --> 06:47.080
So we have demo and admin.

06:47.090 --> 06:51.770
If we go to admin, we'll go to admin as we did before.

06:51.770 --> 06:54.620
But if we go to demo, let's see what will happen.

06:54.830 --> 06:59.060
So let's go to the at the end of the our evil demo.

07:03.730 --> 07:06.550
And nothin is happening here.

07:06.550 --> 07:08.950
I think I need to put a blank.

07:11.850 --> 07:12.420
Bad.

07:12.450 --> 07:20.130
So let me refresh it again and let's come back here so you can see first message from views.

07:20.130 --> 07:21.540
So what is happening here?

07:21.540 --> 07:24.510
We have our URL and then we have slash demo.

07:24.510 --> 07:30.180
So we are coming from here, which is main URL for our project.

07:30.180 --> 07:37.980
Slash demo will send us two demo URLs and demo URLs, which is our application URLs.

07:38.070 --> 07:39.180
Has that.

07:39.180 --> 07:43.230
So empty path will use this view.

07:43.230 --> 07:49.470
And this view is a simple function that will return the string and that's the reason we see that string

07:49.470 --> 07:50.250
here.

07:50.340 --> 07:54.390
So if we would like to have this.

07:55.230 --> 07:59.040
Part something else, let's say first.

08:00.270 --> 08:02.910
Function like that.

08:04.570 --> 08:07.420
If I will copy that URL now.

08:08.360 --> 08:15.680
And if I would go to demo, this site is not available because demo and slash and not an else.

08:15.710 --> 08:17.510
It's not acceptable anymore.

08:17.540 --> 08:25.010
We have demo first function so I can go at the end and I can do first function here and you can see

08:25.040 --> 08:27.620
first message from the views is displayed.

08:27.620 --> 08:36.140
So it's really up to us how we will design our URLs and what will be URLs to use a specific parts of

08:36.140 --> 08:37.190
our application.

08:37.190 --> 08:39.440
We don't need to stick with one function.

08:39.530 --> 08:41.990
We don't need to stick with function at all.

08:41.990 --> 08:48.080
I will show you later on how we can actually use a more sophisticated way to display something on the

08:48.080 --> 08:48.410
screen.

08:48.410 --> 08:51.440
But this is very simple example how we can do it.

08:51.440 --> 08:57.650
So in our case it's just a simple function that return Http response and a simple text here.

08:58.610 --> 09:07.460
But in this URL you might have a lot of them and each of these will have a different URL so you can

09:07.460 --> 09:08.400
build a level.

09:08.420 --> 09:15.830
So you have main application and then demo will be first level like a folder and another folder will

09:15.830 --> 09:18.400
be here and you might have more than one here.

09:18.410 --> 09:23.090
So basically that's how URL works and we'll stick with that pattern.

09:23.090 --> 09:29.090
So basically the main URL will be whatever that is at the moment is localhost, but later on it will

09:29.090 --> 09:35.840
be your production server and then you have it here, then you have port slash and we go, we go here.

09:35.840 --> 09:40.520
If you go demo, you will go to the demo application and you will go URLs here.

09:40.520 --> 09:47.420
And then you have another level, which is another part which is will be slash, demo, slash whatever

09:47.420 --> 09:48.380
is in here.

09:48.380 --> 09:49.820
So we can do first.

09:51.690 --> 09:53.280
First for Shorter.

09:55.200 --> 09:57.360
And then we will display it here.

09:57.360 --> 09:59.940
So that's how URLs work.

09:59.940 --> 10:07.860
And later on I will show you also how we can include all the URLs that are available for our views,

10:07.860 --> 10:09.660
but class based view.
