Search⌘ K

Code Templates in Django

Explore how to create a templates directory, configure Django settings to find templates, and build a basic HTML template. Learn to pass data from views.py to templates using context dictionaries and render dynamic content in your Django application.

Example of a template

For this example, we will use the example from the Variables lesson. We already know some of these steps, but we will go through them once again to help reinforce the concepts.

We need to perform the following steps:

Step 1: Create a templates directory

First, we will create a templates directory in the outermost first_project directory. Then, inside the templates directory, we will add another directory by the name of our application, called first_app, such that the hierarchy becomesfirst_project/templates/first_app/.

Step 2: Tell Django where to find templates

As we saw in the previous lesson, we have to ...