Django template path settings: templates, TEMPLATE_DIRS, TEMPLATES,

Source: Internet
Author: User

Django template path settings: templates, TEMPLATE_DIRS, TEMPLATES,

Django version: 1.9.5

First, set templates to the same directory as manage. py, and then the template file under templates.

Then set settings. py: Pay attention to the modification of the yellow area.

TEMPLATES = [    {        'BACKEND': 'django.template.backends.django.DjangoTemplates',        'DIRS': [os.path.join(BASE_DIR, 'templates').replace('\\', '/'),],        #'APP_DIRS': True,        'APP_DIRS': False,        'OPTIONS': {            'context_processors': [                'django.template.context_processors.debug',                'django.template.context_processors.request',                'django.contrib.auth.context_processors.auth',                'django.contrib.messages.context_processors.messages',            ],        },    },]

If 'app _ dirs': True, you can directly search for templates in the APP directory. This is the default setting. Therefore, you can simply put the templates folder under the app.

'App _ dirs': False. If it is set to False, it will not be searched in the APP, but will be searched based on the path in DIRS.
The above two methods are successfully tested!

It may be due to version issues. The previous version should have a parameter:
TEMPLATE_DIRS = (OS. path. join (BASE_DIR, ''templates'). replace ('\', '/'),) settings
This method was not successfully tested in 1.9.5.
Django version updates will indeed bring a lot of learning costs.

Related Article

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: 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.