Details about the templates settings in the Python Django framework, djangotemplates

Source: Internet
Author: User

Details about the templates settings in the Python Django framework, djangotemplates

TEMPLATES

New Features of Django 1.8
A list containing all template engine settings used in Django. Each item in the list is a dictionary that contains an engine option.

The following is a simple setting that tells the Django template engine to read the template from the templates subdirectory of the installed application (installed applications:

TEMPLATES = [  {    'BACKEND': 'django.template.backends.django.DjangoTemplates',    'APP_DIRS': True,  },]

The following options are available for all engines.
BACKEND

Default: no definition
The template engine used. Built-in template engines include:

  'django.template.backends.django.DjangoTemplates'  'django.template.backends.jinja2.Jinja2'

By setting BACKEND to a full (fully-qualified) path (for example, 'mypackage. whatever. backend'), you can use a non-Django built-in engine.
NAME

Default Value: See the following figure.
The alias of the template engine. It is an identifier that allows you to select an engine during rendering. Aliases must be unique among all configured template engines.
If no value is provided, the Template Name of the engine class is defined by default, that is, the last part adjacent to the BACKEND.
For example, if the engine is 'mypackage. whatever. backend', its default name is 'whatever '.
DIRS

Default Value: [] (empty list)
The engine is used to find the directory of template source files in the order of search.
APP_DIRS

Default Value: False
Whether the engine finds the template source file in the directory of the installed application.
OPTIONS

Default: {} (empty dictionary)
Other parameters passed to the template engine (backend. Different engines have different available parameters.
TEMPLATE_CONTEXT_PROCESSORS

Default Value:

("django.contrib.auth.context_processors.auth","django.template.context_processors.debug","django.template.context_processors.i18n","django.template.context_processors.media","django.template.context_processors.static","django.template.context_processors.tz","django.contrib.messages.context_processors.messages")

Versions earlier than 1.8 do not support the following:
Set the 'Context _ processors 'option in OPTIONS of a DjangoTemplates engine.

The tuples used to fill in the context of the RequestContext call function (callables. These functions obtain a request object as its parameter and return a dictionary to be filled into the context project.

  • Django 1.8 changes:
  • In Django 1.8, the context processor of the built-in template moves from django. core. context_processors to django. template. context_processors.

TEMPLATE_DEBUG

Default Value: False

Versions earlier than 1.8 do not support the following:
Set the 'debug' option in OPTIONS of a DjangoTemplates engine.

A boolean value that enables/disables the template debugging mode. If the value is True, any exception thrown during template rendering will display a lovely error page with detailed reports. This page contains the code snippet related to the template and uses the appropriate line to highlight it.
Note that if DEBUG is True, Django only displays the cute error page.
See DEBUG.
TEMPLATE_DIRS

Default: () (empty list)

Versions earlier than 1.8 do not support the following:
Set the 'dirs' option in a DjangoTemplates engine.

Django. template. loaders. filesystem. Loader searches for the path list of the template source code in the order of search.
Note that even in Windows, these paths use Unix-style forward slashes.
See The Django template language.
TEMPLATE_LOADERS

Default Value:

('django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader')

Versions earlier than 1.8 do not support the following:
In the OPTIONS of a DjangoTemplates engine, set the 'loader 'option.

The tuples of the template reader class, which are specified by strings. Each reader class knows how to import a template from a specific source. Optional. You can also use a single tuple instead of a string. The first item in the tuples should be the reader module, and the subsequent item is passed to the reader during initialization. See The Django template language: for Python programmers.
TEMPLATE_STRING_IF_INVALID

Default Value: ''(Null String)

  • Versions earlier than 1.8 do not support the following:
  • Set the 'string _ if_invalid' option in OPTIONS of a DjangoTemplates engine.

The string output by the template system when an unavailable (such as spelling error) variable is used. See How invalid variables are handled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.