I'm having a bit of difficulty understanding the way Django looks for template files.
I'm following a tutorial, and in (project directory)/thirdauth/settings.py, I have the following:
# See: http://stackoverflow.com/questions/15411164/django-templates-folders
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = [
os.path.join(PROJECT_ROOT, 'thirdauth_app/templates'),
]
In (project root)/thirdauth/urls.py, I have the following:
urlpatterns = [
url(r'^$', include('thirdauth_app.urls')),
url(r'^admin/', admin.site.urls),
]
Then in (project root)/thirdauth_app/urls.py I have this:
from . import views # <- why?
urlpatterns = [
url(r'^$', views.home, name='home')
]
(Though as my comment indicates, I'm not exactly sure why I have to import views explicitly in an app when this isn't necessary in (project root)/thirdauth/urls.py, but I suppose that's a separate question.)
In (project_root)/thirdauth_app/views.py is the following:
def home(request):
context = RequestContext(request, {'user': request.user})
return render_to_response('thirdauth_app/home.html', context_instance=context)
Finally, the template file itself is located at (project root)/thirdauth_app/templates/thirdauth_app/home.html
Unfortunately, when running the server, I'm still getting the TemplateDoesNotExist error (TemplateDoesNotExist at /)
Obviously I've misunderstood something crucial, so any advice would be hugely appreciated.
Edit: Per request, here is the full traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.9.1
Python Version: 2.7.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'thirdauth']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine :
* django.template.loaders.app_directories.Loader: /home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/contrib/admin/templates/home.html (Source does not exist)
* django.template.loaders.app_directories.Loader: /home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/contrib/auth/templates/home.html (Source does not exist)
Traceback:
File "/home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/dbc/venv_projects/thirdauth/thirdauth/thirdauth_app/views.py" in home
7. return render_to_response('home.html', context_instance=context)
File "/home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/shortcuts.py" in render_to_response
45. using=using)
File "/home/dbc/venv_projects/thirdauth/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
137. raise TemplateDoesNotExist(template_name, chain=chain)
Exception Type: TemplateDoesNotExist at /
Exception Value: home.html