8

I am facing strange very issue today. I am getting TemplateDoesNotExist (see first image) but when I tried to debug the template source with debug-toolbar it is correctly showing the templates path (see image 2) More strangely, when I clicked on specific templates button it is correctly showing the source of template.

This is the first time I am facing such issues. Can someone please explain why I am getting this error.

EDIT: Adding settings.py file(relavant portion)

SETTINGS_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(SETTINGS_PATH, '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',
        ],
    },
},

]

Thanks

enter image description here

enter image description here)

user3265443
  • 535
  • 1
  • 8
  • 25
  • Instead of posting hard to read images of text, *post the actual text*... along with the necessary information to reproduce the bug – Sayse Jan 28 '16 at 20:20
  • I just want to understand why I am getting TemplateDoesNotExist exception even though template exists on the path? Check the 2nd image when I click on "Templates" on debug-toolbar..(right side)... Please help me to understand the issue...I am stuck on this for very long time – user3265443 Jan 28 '16 at 20:42
  • You should include any useful parts of the trace from the exception. – Jmills Jan 28 '16 at 21:08
  • @TheCardCheat I think I am facing similar issue to this question (http://stackoverflow.com/questions/1926049/django-templatedoesnotexist) but when I am running this command "chown root ./*"... I am getting Operation not permitted – user3265443 Jan 28 '16 at 21:10
  • @user3265443 That question's accepted answer is a pretty straightforward explanation of the default django template loading, which unless you have altered or do not have 'registration' in your INSTALLED_APPS would seem to be in order (assuming debug-toolbar is accurate, I don't use it). Why are you trying to chown root things? If you are messing with params then you may be getting an access exception that is causing that template not to be loaded, so it is still useful to see the stack trace text. – Jmills Jan 28 '16 at 21:18
  • @TheCardCheat I have added settings.py file..Its the default setting file only. Author of the question(stackoverflow.com/questions/1926049/django-templatedoesnotexist) ) have written the answer in a EDIT – user3265443 Jan 28 '16 at 21:28

2 Answers2

13

I had the similar issue with Django 1.9 . I just changed the DIRS in TEMPLATES of settings.py file.

Try this

'DIRS': [os.path.join(BASE_DIR,'templates')],

Instead of your

'DIRS':[os.path.join(SETTINGS_PATH,'templates')], 

Try this code instead of your TEMPLATES

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(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',

        ],
    },
},] 
5

I upgraded to 1.9 today and suddenly had the same problem. For me it seems that adding " 'APP_DIRS': True, " to the templates does the trick (I toggled a few times by adding/deleting this and it works/fails).

So what does APP_DIRS do: if I understand the documentation ( https://docs.djangoproject.com/en/1.9/ref/templates/api/ ) correctly it reads the default Django templates if True. Basically, for 95% of all projects this should be the case.

MZA
  • 999
  • 11
  • 16