What You'll Learn in This Hour |
|
So far, all the examples of web pages that you have created in your views have been hard-coded by Python code that generates an HTML web page. This has worked well because the web pages that you have created have been basic.
As you create more advanced web pages, you will want to begin using the Django template system. The Django template system allows you to write template files that define the presentation of the web page independent of the data. This means that you can write generic web pages and then use the Python code in the views to generate dynamic content inside them.
Using the template system has several benefits. For example, an HTML developer could be working on the web page views, and a Python developer could be working on processing the data at exactly the same time.
In this hour, you will get a chance to create some HTML templates and use them to render the data in your views.
The first step in adding templates to your website is to create and configure a directory to store them in. You will want to create at least one directory to store the templates in and then add that directory to the TEMPLATE_DIRS setting in the project's settings.py file.
Django's template engine will read the TEMPLATE_DIRS setting and use the directories that are configured there to process the relative paths you will specify for the template.