tutorial on setting up templates items in the Django framework of Python

Source: Internet
Author: User
TEMPLATES

New features of Django 1.8
A list that contains all the settings for the template engine used in Django. Each item in the list is a dictionary that contains the options for an engine.

Here 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 (backends).
Backend

Default: No definition
The template engine used. The built-in template engine is:

  ' 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-brought engine.
NAME

Default: See below
The alias of the template engine. It is an identifier that allows you to select an engine when rendering. Aliases must be unique in all configured template engines.
When a value is not provided, the default is to define the template name of the engine class, which is the last part adjacent to the backend.
For example, if the engine is ' mypackage.whatever '. Backend ', then its default name is ' whatever '.
DIRS

Default: [] (Empty list)
The directory that the engine uses to find template source files, sorted by search order.
App_dirs

Default: False
Whether the engine looks for template source files within the installed application (directory).
OPTIONS

Default: {} (Empty dictionary)
Other parameters passed to the template engine (backend). Different engines, the available parameters are not the same.
Template_context_processors

Default:

("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 ")

Since the 1.8 release, the use is not supported:
In a djangotemplates engine the options set the ' context_processors ' option to replace.

The tuple that is used to populate the calling function (Callables) of the context in RequestContext. These functions take a request object as its argument and return a dictionary that will be populated into the context item.

    • Changes to Django 1.8:
    • In Django 1.8, the context processor for the built-in template is moved from django.core.context_processors to Django.template.context_processors.

Template_debug

Default: False

    • Since the 1.8 release, the use is not supported:
    • In a djangotemplates engine the options set the ' Debug ' option to replace.

A Boolean value that opens/closes the template debug mode. If the value is true, any exceptions thrown during template rendering will display a cute, detailed report of the error page. The page contains the code snippet associated with the template and is highlighted with the appropriate row.
Note If debug is True,django only the cute error page will be displayed.
See DEBUG.
Template_dirs

Default: () (Empty list)

    • Since the 1.8 release, the use is not supported:
    • Set the ' DIRS ' option in a djangotemplates engine instead.

Django.template.loaders.filesystem.Loader The path list of the search template source code, sorted by search order.
Note Even in Windows, these paths are a forward slash that uses UNIX style.
See the Django template language.
Template_loaders

Default:

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

    • Since the 1.8 release, the use is not supported:
    • In a djangotemplates engine the options set the ' loader ' option to replace.

The tuple of the template reader class, specified with a string. Each reader class knows how to import a template from a specific source (particular source). Optionally, you can also use a tuple instead of using a string. The first item in the tuple should be the reader's module, and subsequent entries are passed to the reader at initialization time. See the Django template language:for Python programmers.
Template_string_if_invalid

Default: ' (empty string)

    • Since the 1.8 release, the use is not supported:
    • In a djangotemplates engine the options set the ' string_if_invalid ' option to replace.

A string that is output by the template system when an unusable (such as a misspelling) variable is used. See how invalid variables is 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.