Write and Run the Tests for the Templates

Learn to write tests for templates in Django.

We'll cover the following

As we know, Django follows the Model-View-Template model. For our models, we’ve written both the test and the code. We discussed the view and also the template. However, we haven’t yet created a complete test suite for the template. This is what this particular lesson will focus on.

Note: It’s an iterative process to program an application. We go to the next piece of functionality as one is programmed out.

This project’s template is only a single file called index.html that was prepared in the previous session. This is where the code that users view on the web application’s homepage is stored.

Test the template

The whole test for our template is shown below. It also shows the numerous test methods we’ll use as we iterate through our codebase to ensure that the required output is visible on the home page:

Get hands-on with 1400+ tech skills courses.