Django template dir strange behaviour
Question: I am really having problems to set TEMPLATE_DIR correctly after searching
through bunch of topics and trying various things.

Here are my project settings:

    
    
    #settings.py
    DEBUG = True
    TEMPLATE_DEBUG = DEBUG
    import os
    PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
    
    MEDIA_ROOT = ''
    MEDIA_URL = ''
    
    STATIC_ROOT = ''
    STATIC_URL = '/static/'
    STATICFILES_DIRS = (
        PROJECT_PATH + '/static/',
    )
    
    STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.FileSystemFinder',
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )
    
    TEMPLATE_LOADERS = (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )
    TEMPLATE_DIRS = (
        PROJECT_PATH + '/TrainingBook/templates/',
        PROJECT_PATH + '/RestClient/templates/',
    )
    
    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'TrainingBook',
    )
    
    TEMPLATE_CONTEXT_PROCESSORS = (
        "django.core.context_processors.debug",
        "django.core.context_processors.i18n",
        "django.core.context_processors.media",
        "django.core.context_processors.static",
        # 'django.core.context_processors.request',
        "TrainingBook.context_processors.global_context",
    )
    print PROJECT_PATH # /Users/Kuba/Development/University/RestClient
    print STATICFILES_DIRS # ('/Users/Kuba/Development/University/RestClient/static/',)
    print TEMPLATE_DIRS 
    # ('/Users/Kuba/Development/University/RestClient/TrainingBook/templates/',
    # '/Users/Kuba/Development/University/RestClient/RestClient/templates/')
    

My project structure:

    
    
    $ pwd
    /Users/Kuba/Development/University/RestClient
    $ tree
    .
    ├── RestClient
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── settings.pyc
    │   ├── templates
    │   │   ├── base.html
    │   │   ├── home.html
    │   │   └── login_form.html
    │   ├── urls.py
    │   ├── urls.pyc
    │   ├── wsgi.py
    │   └── wsgi.pyc
    ├── TrainingBook
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── context_processors.py
    │   ├── context_processors.pyc
    │   ├── models.py
    │   ├── models.pyc
    │   ├── templates
    │   │   ├── friends.html
    │   │   ├── statistics.html
    │   │   └── workouts.html
    │   ├── tests.py
    │   ├── views.py
    │   └── views.pyc
    ├── manage.py
    ├── settings.py
    ├── settings.pyc
    └── static
        ├── css
        │   ├── bootstrap-glyphicons.css
        │   ├── bootstrap.css
        │   ├── bootstrap.min.css
        │   └── main.css
        └── js
            ├── bootstrap.js
            ├── bootstrap.min.js
            └── jquery-1.10.2.js
    

I moved "settings.py" one level up in order to get PROJECT_PATH set to
"/RestClient/" instead of "/RestClient/RestClient/".

I also modified manage.py from

    
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "RestClient.settings")
    

to

    
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    

When I run server TemplateDoesNotExist is raised and I am seeing something
strange:

    
    
    Template-loader postmortem
    
    Django tried loading these templates, in this order:
    Using loader django.template.loaders.filesystem.Loader:
    /Users/Kuba/Development/University/RestClient/TrainingBook/templates/templates/home.html (File does not exist)
    /Users/Kuba/Development/University/RestClient/RestClient/templates/templates/home.html (File does not exist)
    Using loader django.template.loaders.app_directories.Loader:
    /Users/Kuba/.virtualenvs/client/lib/python2.7/site-packages/django/contrib/auth/templates/templates/home.html (File does not exist)
    /Users/Kuba/Development/University/RestClient/TrainingBook/templates/templates/home.html (File does not exist)
    

As you can see there is "/templates/templates" even though I didn't specify it
so.

On the other hand if I switch TEMPLATE_DIRS to:

    
    
    TEMPLATE_DIRS = (
        PROJECT_PATH + '/TrainingBook/',
        PROJECT_PATH + '/RestClient/',
    )
    

after TemplateDoesNotExist is raised I can see that loader was looking for
templates at:

    
    
    /Users/Kuba/Development/University/RestClient/RestClient/home.html
    /Users/Kuba/Development/University/RestClient/TrainingBook/home.html
    

What did I do wrong?

EDIT: The problem was that I defined some views like this:

    
    
    class Home(Base):
        template_name = 'templates/home.html'
    


Answer: You specified `templates/home.html` instead of just `home.html`.

A template name will be appended to a TEMPLATE_DIRS, so `/foo/templates/` as
TEMPLATE_DIRS will become `/foo/templates/templates/home.html` if
`templates/home.html` is a template name. Instead, the template name should be
just `home.html` and the resulting template path would be
`/foo/templates/home.html` which is correct.

