1from pathlib import Path
2
3BASE_DIR = Path(__file__).resolve().parent.parent
4TEMPLATES_DIR = [BASE_DIR.joinpath('template1'), ]
5TEMPLATES = [
6 {
7 'BACKEND': 'django.template.backends.django.DjangoTemplates',
8 'DIRS': TEMPLATE_DIRS,
9 'APP_DIRS': True,
10 'OPTIONS': {
11 'context_processors': [
12 'django.template.context_processors.debug',
13 'django.template.context_processors.request',
14 'django.contrib.auth.context_processors.auth',
15 'django.contrib.messages.context_processors.messages',
16 ],
17 },
18 },
19]
1# to add a templates folder to django project you need to add it under TEMPLATES > DIRS
2
3# settings.py
4TEMPLATES = [
5 {
6 'BACKEND': 'django.template.backends.django.DjangoTemplates',
7 'DIRS': [BASE_DIR / 'templates', BASE_DIR / 'app/templates'] # add here
8 ,
9 'APP_DIRS': True,
10 'OPTIONS': {
11 'context_processors': [
12 'django.template.context_processors.debug',
13 'django.template.context_processors.request',
14 'django.contrib.auth.context_processors.auth',
15 'django.contrib.messages.context_processors.messages',
16 ],
17 },
18 },
19]
1PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
2
3TEMPLATE_DIRS = (
4 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
5 # Always use forward slashes, even on Windows.
6 # Don't forget to use absolute paths, not relative paths.
7 os.path.join(PROJECT_ROOT, 'templates').replace('\\','/'),
8)
9
10# List of callables that know how to import templates from various sources.
11TEMPLATE_LOADERS = (
12 'django.template.loaders.filesystem.Loader',
13 'django.template.loaders.app_directories.Loader',
14# 'django.template.loaders.eggs.Loader',
15)
16