Last active
June 23, 2019 14:10
-
-
Save cadu-leite/54bec8a55287948780f3317d661916e1 to your computer and use it in GitHub Desktop.
List all Django Templates Directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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