Django Template path settings: templates,template_dirs,templates

Source: Internet
Author: User

Django Version: 1.9.5

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

Then set settings.py: Notice to change the yellow place.

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, look for templates directly in the app's directory, this is the default setting, so the simplest is to put the Templates folder directly under the app.

' App_dirs ': false, set to false, will not go to the APP to find, but based on the path in the DIRS to find.
The above two methods of testing success!


This may be due to a version issue, the previous version should have a parameter:
(    os.  Path.  Join(base_dir, 'templates ').  Replace('\ \'/'),set
This method was not tested successfully in 1.9.5.
The Django version update does bring a lot of cost to learning.

Django Template path settings: templates,template_dirs,templates

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.