Reputation: 373
I have a templates directory /var/opt/backoffice/templates and inside there is a template called foo.html. The directory is outside the Django root directory, which is /opt/backoffice.
I am trying to get Django to access the foo.html template in /var/opt/backoffice/templates using the get_templates('foo.html') command, but no matter what I try I get the error: django.template.exceptions.TemplateDoesNotExist: foo.html
My settings.py for templates is:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'var/opt/backoffice/templates'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
My question is , how can I configure Django so that I can access the template in /var/opt/backoffice/templates using get_templates('foo.html')?
Thank you.
Upvotes: 0
Views: 494
Reputation: 422
You're missing a slash before var
, that makes it a subdirectory rather than a root level dir:
'DIRS': [
'/var/opt/backoffice/templates'
],
I did not check with /var
but it did work for me in another folder of my home directory outside of the Django project
Upvotes: 1