Django Template Does Not Exist
Question: I know this has been covered already but none of the solutions have worked for
me. I have a basic django project and it cannot find the template. Here is my
views.py:

    
    
    now = datetime.datetime.now()
    t = get_template('index.html')
    html = t.render(Context({'current_date' : now}))
    return HttpResponse(html)
    

This is my TEMPLATE_DIRS in settings.py. The project is specified under
INSTALLED_APPS

    
    
    TEMPLATE_DIRS = (
        '/Users/Howie/Desktop/djangoCode/mysite/Movies/templates/',
    )
    

This is the error I get every time

    
    
    Template-loader postmortem:
    Django tried loading these templates, in this order:
    Using loader django.template.loaders.filesystem.Loader:
    C:\Users\Howie\Desktop\djangoCode\mysite..\templates\index.html (File does not exist)
    Using loader django.template.loaders.app_directories.Loader:
    C:\Python34\lib\site-packages\django-1.7.2-py3.4.egg\django\contrib\admin\templates\index.html (File does not exist)
    C:\Python34\lib\site-packages\django-1.7.2-py3.4.egg\django\contrib\auth\templates\index.html (File does not exist)
    C:\Users\Howie\Desktop\djangoCode\mysite\Movies\templates\index.html (File does not exist)
    

I don't understand why django cant find my index.html file. I've tried moving
the templates folder into the app itself(named Movies) and I've also had it in
the root project folder but both of those didn't work. Any insight would be
helpful.


Answer: The
[app_directories.Loader](https://docs.djangoproject.com/en/1.7/ref/templates/api/#django.template.loaders.app_directories.Loader)
is enabled by default. This means you can put your template in an
`app/templates` directory and be done. No need for TEMPLATE_DIRS and/or
TEMPLATE_LOADERS settings. Just out of the box Django:

project/app/views.py  
project/app/templates/index.html

    
    
    get_template('index.html')
    

It's even better to [use
subdirectories](https://docs.djangoproject.com/en/1.7/ref/templates/api/#using-
subdirectories):

project/app/views.py  
project/app/templates/app/index.html

    
    
    get_template('app/index.html')
    

This to avoid a index.html from some other app to take precedence.

If you really want a template folder in the root of your project, than don't
use hardcoded paths. Do something like
[this](https://github.com/twoscoops/django-twoscoops-
project/blob/develop/project_name/project_name/settings/base.py):

    
    
    from os.path import abspath, dirname, join, normpath
    from sys import path
    
    SITE_ROOT = dirname(dirname(abspath(__file__)))
    TEMPLATE_DIRS = (
        normpath(join(SITE_ROOT, 'templates')),
    )
    

