How templates work
Django renders templates while being agnostic of the actual template engine, as the following diagram shows:
Simplified depiction of template rendering in Django
Each template is rendered by trying each template backend specified by the TEMPLATES
variable in settings.py
in order.
A Loader object corresponding to the backend will search for the template. Based on the backend's configuration, several kinds of loaders will be used. For instance, filesystem.Loader
loads templates from the filesystem according to DIRS
, and app_directories.Loader
loads templates from within app directories.
If a Loader is successful, the search ends and that particular backend template engine is chosen for rendering. This results in a Template object, which contains the parsed and compiled template.
To render a Template, you will need to provide it with a Context object. Context behaves exactly like a dictionary, but is implemented as a stack of dictionaries. If a Template is a container for placeholders...