THE TEMPLATES

Templates are nothing more than html files set in the views in the render method.
Django

templates
templates
templates

The render method accepts three parameters, the request, the html file we want to render and a third parameter, the context which is a data dictionary in which we are going to specify what we want to display in the html page. We will be able to set up the html file so that it displays articoli and giornalisti.

Views

We decide where the html file resides, we go to the settings.py file of the project. We scroll through the file until we reach the TEMPLATES item. In the file there is an item called BASE_DIR (Base Directory) which coincides with the project Directory. Let’s create a new folder called templates in which we will put the html file.

TIP: When creating the html file if you do not have the completion of the HTML code follow this procedure: Go to File-> Preferences-> Settings and specify the values shown in the figure in “Emmet: Include Languages”. Restart Visual Studio Code.

dirs
Emmet

Once the HTML file has been created, we pass the data of articoli and giornalisti defined in the context of the view to the Django template engine where we define, how the data passed by the view should be displayed. The difference in using two curly brackets and the percentage is the fact that the double square bracket specifies a value that we are taking from the context, while the percentage specifies a Django template engine tag.

html

LINKS TO PREVIOUS POST

PREVIOUS POST LINKS

LINK TO THE CODE ON GITHUB

GITHUB