django load settings to template code example
Example: how to get all template project in settinge use django
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
class InvalidTemplateVariable(str):
def __mod__(self,other):
from django.template.base import TemplateSyntaxError
raise TemplateSyntaxError("Invalid variable : '%s'" % other)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['%s/templates/' % (PROJECT_DIR),'%s/dev_templates/' % (PROJECT_DIR),],
'APP_DIRS': True,
'OPTIONS': {
'string_if_invalid': InvalidTemplateVariable("%s"),
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]