Performance: Template configuration and directories
This affects the server-side rendering speed and initial page load time by determining how templates are found and loaded.
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {},
}]TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/absolute/path/to/templates', '/another/absolute/path'],
'APP_DIRS': False,
'OPTIONS': {},
}]| Pattern | Filesystem Checks | Template Cache Usage | Server Response Impact | Verdict |
|---|---|---|---|---|
| Multiple absolute DIRS, APP_DIRS=False | High (multiple dirs checked) | No | Increases response time by 50-100ms | [X] Bad |
| Single relative DIRS, APP_DIRS=True | Low (cached app dirs) | Yes | Reduces response time by up to 70% | [OK] Good |
TEMPLATES['DIRS'] setting in Django?TEMPLATES['DIRS']TEMPLATES['DIRS'] [OK]APP_DIRS=True tells Django to look inside each app's templates folder automatically.APP_DIRS=False disables this feature; manually adding paths is not automatic; installed apps list alone doesn't find templates.APP_DIRS=True in the TEMPLATES setting -> Option CAPP_DIRS=True [OK]settings.py snippet: TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {},
}]DIRS settingAPP_DIRS settingAPP_DIRS=True, Django also searches inside each app's 'templates' folder.APP_DIRS=False but your templates inside app folders are not found. What is the best fix?APP_DIRS=FalseAPP_DIRS=False, Django does not look inside app template folders automatically.APP_DIRS=True tells Django to find templates inside app folders without manual paths.APP_DIRS=True to enable automatic app template loading -> Option BTEMPLATES to achieve this?APP_DIRS=True allows Django to find templates inside each app's templates folder.DIRSDIRS lets Django find templates used across the whole project.APP_DIRS=True and add the shared templates folder path to DIRS -> Option APass the test and this pattern moves unknown