python - Django Global base.html template -
i new django. using django 1.8.6 python 2.7. trying use base.html template can used globaly through out entire site, every app , access it. here test site's current structure:
twms
polls
migrations
static
templates
project
migrations
static
templates
project
index.html
tmws
static
templates
tmws
base.html
here code project/templates/project/index.html
{% extends 'tmws/base.html' %} {% block content %} <h1>projects</h1> <ul> {% project in project_list %} <li><a href="{% url 'project:detail' project.id %}">{{ project.name }}</a></li> {% endfor %} </ul> end of list {% endblock %} this error receiving:
templatedoesnotexist @ /project/
tmws/base.html
how access tmws/tmws/templates/tmws/base.html of apps?
any appreciated!
let me know if additional information needed.
edit
here template settings settings.py:
templates = [ { 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [ os.path.join(base_dir, 'templates'), # if leave both or comment 1 one out still same error 'tmws.tmws.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', ], }, }, ]
i think might having problem template directory configuration. in project´s settings.py try check if have configuration similar one:
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) templates = [ { 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [os.path.join(base_dir, 'your template dir name')] , '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', ], }, }, ] where 'your template dir name' should tmws. make django search directory whenever try extend templates in html. can add many directories want.
i think right django must searching template in:
twms/project/templates/project so maybe if place base.html file there django able find it.
another suggestion create general templates directory , place base.html there since want used in entire site. taste ordering templates, should work either way.
edit:
adding following in settings.py solved problem. read comments more info:
master_base_dir = os.path.dirname(__file__) templates = [ { 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [os.path.join(master_base_dir, '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', ], }, }, ]
Comments
Post a Comment