Okay.
Let's talk about URLs in this video.
So inside our project, if we open our project here, we have URLs and that's main URLs that are responsible
for our routing in our application.
So if will open this, I can actually remove all that, but feel free to read this.
That's very useful information here.
What kind of different URLs we might use in our application, but I will remove it from here.
So what's happening here is that we have at the moment one URL, one extra URL, because if we go to
this base URL, I can see here that basic Django site is displayed and it means really nothing because
it's just a placeholder for application.
It's telling us that this is the Django has been successfully installed, but we need to do our own
URLs and if we come back to our application here at the moment we have admin and we already visited
admin here.
So what we can do here and this is on the project level, we can do a reference to another URL file.
So what I will do is I will go to the demo and I will create another URL file.
So new file.
Right click on the folder, new file and then I will do urls.
PY and I have two files.
URLs.
Basically I will close others and I have one file that is for the project which is main file and another
for our application.
What I can do is basically I will copy what I have here and I will paste it for now here and in this
part I can leave it blank.
We don't have anything here for now, but I will add it later on.
So what we can do is we might have some kind of folders in our URL.
So if I will go to.
At the end to slash demo and then slash something.
I will use URL URLs from this application.
So basically on the main project URLs, I will have that reference to demo and that will reference another
file and I will go deeper and deeper and I might have a more than one level.
It's all depend on us.
So basically what we need to do is we need to add extra path here.
I will just duplicate it here and I will do demo and wherever we go to demo we will need to do include.
We need to also import that include from URLs.
So include will give us an option to include some other urls.
So urls is sorry, demo dot URLs.
So basically what we are doing here, if we fill in our URL, we'll have a demo.
We will include the URLs from this file which is inside the demo.
So we might have another level here.
So if I will save it now and then I will.
Refresh it like this.
And if going to be rich.
Probably our server is not working at the moment because we need to include some extra information.
So we need to go here and then we need to do something there.
So basically what we will do, I will finish this exercise first and I will show you how it works later
on.
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,
which is kind of empty path, but that will be on the level demo is already we are in the demo and then
we'll use our views and in views I can open views.
We don't have anything here.
So what we can do is we can create a simple function.
So let's say first function here, and that's our definition first.
And then so request will be part of this.
We're not going to use it here.
We will do return simple Http response and we need to import that.
So from.
Django http.
Import that http response.
And in this http response, what we can do is we can include some something.
So.
First search from views will include that.
And that's a simple function we have in our Python on the views level so that first I can use it here.
So what we need to do first we need to import so from current folder import views and that views are
available here and inside here I can do views.
And I can do.
First I need to call it.
So it is a reference to our view first.
So now I will run the server and we don't have any issues.
Now if we come back here and then I will refresh this changed.
This changed because now we have our URLs in place, so there is no default page displayed with the
Django.
Now we have this demo and this admin, by the way, you see that screen because you have the back through
in the settings file.
So if you will put your application on the server, it will be better to go to the settings.
And the back change it to false here.
So for us to work on the on the testing environment on our machine, we can have it true because it's
actually very, very handy to see that kind of thing.
So basically the URL without anything here is not acceptable anymore.
We need to put it demo or admin.
And that's coming from our file, which is.
This one URL.
So we have demo and admin.
If we go to admin, we'll go to admin as we did before.
But if we go to demo, let's see what will happen.
So let's go to the at the end of the our evil demo.
And nothin is happening here.
I think I need to put a blank.
Bad.
So let me refresh it again and let's come back here so you can see first message from views.
So what is happening here?
We have our URL and then we have slash demo.
So we are coming from here, which is main URL for our project.
Slash demo will send us two demo URLs and demo URLs, which is our application URLs.
Has that.
So empty path will use this view.
And this view is a simple function that will return the string and that's the reason we see that string
here.
So if we would like to have this.
Part something else, let's say first.
Function like that.
If I will copy that URL now.
And if I would go to demo, this site is not available because demo and slash and not an else.
It's not acceptable anymore.
We have demo first function so I can go at the end and I can do first function here and you can see
first message from the views is displayed.
So it's really up to us how we will design our URLs and what will be URLs to use a specific parts of
our application.
We don't need to stick with one function.
We don't need to stick with function at all.
I will show you later on how we can actually use a more sophisticated way to display something on the
screen.
But this is very simple example how we can do it.
So in our case it's just a simple function that return Http response and a simple text here.
But in this URL you might have a lot of them and each of these will have a different URL so you can
build a level.
So you have main application and then demo will be first level like a folder and another folder will
be here and you might have more than one here.
So basically that's how URL works and we'll stick with that pattern.
So basically the main URL will be whatever that is at the moment is localhost, but later on it will
be your production server and then you have it here, then you have port slash and we go, we go here.
If you go demo, you will go to the demo application and you will go URLs here.
And then you have another level, which is another part which is will be slash, demo, slash whatever
is in here.
So we can do first.
First for Shorter.
And then we will display it here.
So that's how URLs work.
And later on I will show you also how we can include all the URLs that are available for our views,
but class based view.