Django's Settings Templates in the path set

 
## mysite/mysite/settings.py
## mysite是项目名
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], # templates 'APP_DIRS': True, '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', ], }, }, ]

The templates folder is placed in the directory project, all projects or projects in the application of some of the common template

 

## mysite/mysite/settings.py
## mysite/app1/
## mysite是项目名字,app1是应用名字
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'app1/templates')], ## templates 'APP_DIRS': True, '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', ], }, }, ]
This project templates in the following folder inside the application app1, which is dedicated template used in this application app1.

 

#########################

In summary, he said: BASE_DIR refers to the absolute path mysite project.

'DIRS': [os.path.join (BASE_DIR, 'templates')] refers to BASE_DIR / templates folder to fetch the template
'DIRS': [os.path.join (BASE_DIR, 'app1 / templates')] is the guiding BASE_DIR / pick Templates folder app1 / templates file

In general, it should be provided 'DIRS': [os.path.join (BASE_DIR , 'templates')], the templates need to specify the public.
app1 specific templates, placed under app1 / templates, may not be required to specify. To specify a specific templates because in app1.views, as long as the direct write 'app1_index.html', Django server will find templates in the current layer (/ app1) views the file is located, in order to find template 'app1_index.html'.

Public templates specified path, all apps can be called, and convenient.
app-specific templates need not be specified, so that when you want to reuse this app when the need to consider templates path problem.
 
## mysite/mysite/settings.py
## mysite是项目名
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], # templates 'APP_DIRS': True, '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', ], }, }, ]

The templates folder is placed in the directory project, all projects or projects in the application of some of the common template

 

## mysite/mysite/settings.py
## mysite/app1/
## mysite是项目名字,app1是应用名字
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'app1/templates')], ## templates 'APP_DIRS': True, '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', ], }, }, ]
This project templates in the following folder inside the application app1, which is dedicated template used in this application app1.

 

#########################

In summary, he said: BASE_DIR refers to the absolute path mysite project.

'DIRS': [os.path.join (BASE_DIR, 'templates')] refers to BASE_DIR / templates folder to fetch the template
'DIRS': [os.path.join (BASE_DIR, 'app1 / templates')] is the guiding BASE_DIR / pick Templates folder app1 / templates file

In general, it should be provided 'DIRS': [os.path.join (BASE_DIR , 'templates')], the templates need to specify the public.
app1 specific templates, placed under app1 / templates, may not be required to specify. To specify a specific templates because in app1.views, as long as the direct write 'app1_index.html', Django server will find templates in the current layer (/ app1) views the file is located, in order to find template 'app1_index.html'.

Public templates specified path, all apps can be called, and convenient.
app-specific templates need not be specified, so that when you want to reuse this app when the need to consider templates path problem.

Guess you like

Origin www.cnblogs.com/shangping/p/12463416.html