Skip to content

Instantly share code, notes, and snippets.

@cadu-leite
Last active June 23, 2019 14:10
Show Gist options
  • Save cadu-leite/54bec8a55287948780f3317d661916e1 to your computer and use it in GitHub Desktop.
Save cadu-leite/54bec8a55287948780f3317d661916e1 to your computer and use it in GitHub Desktop.
List all Django Templates Directories
# pyton3
# django2.1
import os
from django.apps import apps
from django.conf import settings
def get_templates_directories():
template_directories = []
# Getting templates in the templates directory
for template in settings.TEMPLATES:
for directory in template['DIRS']:
template_directories.append(directory)
# Getting templates from INSTALLED_APPS
for app_mame,app_config in apps.app_configs.items():
path = os.path.join(
app_config.path, 'templates'
)
if os.path.exists(path):
template_directories.append(path)
return template_directories
get_templates_directories()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment