Django Templates

Django Templates is the most important part of any front end developer. All static files as media, css and javascripts are created inside templates directory. When we returned HTTP request then we add it into the templates and find result as per developer requirements.

The main purpose of Django templates is to separate the data representation with the data itself. That means, the browser part is only to render the HTML sent to it by the server, and all the relevant data is given to the template by Django itself. This makes the process much easier and pages render easily as there is less clutter in both the front-end and back-end.

Django templates are capable of displaying more than HTML, they can generate pdf, CSV and other popular formats.

 

TEMPLATES = [

          { 'BACKEND': 'django.template.backends.django.DjangoTemplates',

            'DIRS': [], 'APP_DIRS': True,

            'OPTIONS': { # ... some options here ...

          }, 

     },

]

BACKEND is a dotted Python path to a template engine class implementing Django’s template backend API. The built-in backends are django.template.backends.django.DjangoTemplates anddjango.template.backends.jinja2.Jinja2.

Since most engines load templates from files, the top-level configuration for each engine contains two common settings:

  • DIRS defines a list of directories where the engine should look for template source files, in search order.

  • APP_DIRS tells whether the engine should look for templates inside installed applications. Each backend defines a conventional name for the subdirectory inside applications where its templates should be stored.

  • OPTIONS contains backend-specific settings.

Powered  by Codersarts