Okay.
In this video, I would like to show you a template how we can actually take our views and display the
real page instead of a simple information as we have here.
That's a simple string.
We can actually display the whole page.
I have to say that this is not something that we will use in our tutorial because at the end we will
use Django as our API to serve just the data, not the templates.
But I think it's very crucial to know that Django is also a front end framework.
So it's a full stack, so you can do that with Django.
So I would like to show you the way to do it.
And then if you need to have a static page or the page generated by the Django, you can also do it
with this.
And I think it will help you understand how the junk works in overall.
So let's do a quick video about templates.
So first thing, what we will need to do is we'll need to go to the settings here and then we have option
templates inside templates, we have tears, which is directories.
And then inside here we can specify where do we keep our templates.
At the moment we have no templates so we can decide.
I will name my folder as templates like that.
So I will need to create that folder and I will create it in a main folder here.
So right click new directory and I will name it templates the same as we have here so I can save my
settings here.
And then inside templates there is an empty folder here and I can right click new file and I can name
that file whatever I like.
So I will do.
First
temp HTML like that.
I will copy this because I will need to I will use it later on in in the video.
So I will click okay.
And we have empty file of type HTML.
HTML, which is web page.
So what I can do here is I can type HTML here and then colon five and then I can click tab and you can
see PyCharm will finish writing HTML for me.
I don't need to do all that writing by myself.
HTML do that.
So that's our snippets built in.
PyCharm So what do we have here?
I'm not going to go through all the details here.
That's a small topic, but inside body here I can put something that I would like to have display on
the web page.
So I will do H1 tag here and then I can say this is my first template like that.
So we have our HTML file ready.
So let's come back to our views and let's clean it up a little bit.
What we can do is I can remove that another.
And we can go to here and also save it.
So at the moment we have our first as we had before, and that will use our first method.
So what we can do to display instead of a simple.
String like this to display the whole page.
We need to do use meta render here instead of this Http response and we need to also import it.
So from Django shortcuts import, render and render takes two arguments.
First argument is a request.
We can put it here and the second one instead of a string, it takes an argument of a file.
So it is first.
Temp HTML and this is the name of the file we have here.
So now our definition first.
Instead of returning a simple string, it renders the first temp HTML.
So let's take a look how it works in our around the server now.
Cannot import name another.
The reason for this is probably we have reference here.
Another and we already remove it from our view.
So we'll just remove that part.
I'll run the server.
We have no errors.
So let's come back here and then we have another demo first.
And this is my first template.
You can see this is actually bigger.
If I click right, click in here inspect.
You can see here that the H1 tag, the same tag that I had set up here, H1 so I can do, for example,
H2.
This is my page and I will save it.
If I come back here and then refresh it.
You see, this is my page.
So basically what's happening here is we have created our template and this is a type of HTML inside
our templates in the settings we set, where we keep our templates in the template section.
So we just scroll down to that place and add it to the dirs.
And then in views you use, render, render takes two arguments request and the name of the file and
that's it.
And this is the way you can point from my URL to our HTML.
But at this point this HTML is very static.
So basically we don't have any dynamic data from Django.
And I will also show you how we can do that, how we can take the data from Django and pass it to to
the template.