Django Tutorial · Django Tutorial

Django Templates

Learn all about Django Templates in this comprehensive tutorial.

5 min read intermediate
  • In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let's do that.
  • Open the views.
  • To be able to work with more complicated stuff than "Hello World!

Templates

In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let's do that.

Create a templates folder inside the members folder, and create a HTML file named myfirst.html.

The file structure should be like this:

python

Open the HTML file and insert the following:

Modify the View

Open the views.py file in the members folder, and replace its content with this:

Change Settings

To be able to work with more complicated stuff than "Hello World!", We have to tell Django that a new app is created.

This is done in the settings.py file in the my_tennis_club folder.

Look up the INSTALLED_APPS[] list and add the members app like this:

Then run this command:

python

Which will produce this output:

python

Start the server by navigating to the /my_tennis_club folder and execute this command:

python

In the browser window, type 127.0.0.1:8000/members/ in the address bar.

The result should look like this:

Tutorial image

Module quiz

2 questions
1

Which of the following is true about Django Templates?

2

What is the most common pitfall when working with Django Templates?

Answer all questions to submit.