Reputation: 1523
Im getting a
templatedoesnotexistat / login.html
I copied and paste the settings from another project that worked and can not figure out why it can not find the template files. I have gone over it many times and copied the paths so they should defiantly be right. Its driving me mad
My file structure is
-virtual
-src
-logins
-dashboards
-static
-templates
-login.html
-static
-static-only
-media
settings.py
import os
BASE_DIR = '/Users/user/Documents/Python/virtual/'
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'logins',
'dashboards',
)
ROOT_URLCONF = 'src.urls'
STATIC_URL = '/static/'
TEMPLATE_DIR = (
'/Users/user/Documents/Python/virtual/src/static/templates',
)
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = '/Users/user/Documents/Python/virtual/src/static/static-only/'
MEDIA_ROOT = '/Users/user/Documents/Python/virtual/src/static/media/'
STATICFILES_DIRS = (
'/Users/user/Documents/Python/virtual/src/static/static/',
)
urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'logins.views.login', name='login'),
url(r'^/accounts/auth/$', 'logins.views.auth_view', name='auth_view'),
url(r'^/accounts/dashboard/$', 'dashboards.views.dashboard', name='dashboard'),
url(r'^/accounts/logout/$', 'logins.views.logout', name='logout'),
url(r'^/accounts/invalid/$', 'logins.views.invalid', name='invalid'),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.py
from django.shortcuts import render, render_to_response, RequestContext
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
def login(request):
c = {}
c.update(csrf(request))
return render_to_response('login.html', c)
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/accounts/dashboard')
else:
return HttpResponseRedirect('/accounts/invalid')
def logout(request):
return render_to_response('logout.html')
def invalid(request):
return render_to_response('invalid.html')
Upvotes: 1
Views: 2079
Reputation: 813
In Django 1.8 template_dirs has been deprecated and is now expected to be defined using TEMPLATES["DIRS"]
The DIRS option
Changed in Django 1.8:
This value used to be defined by the TEMPLATE_DIRS setting.
Reference https://docs.djangoproject.com/en/1.8/ref/templates/api/#loader-types
Posting this as answer, since I wasted few hours on identifying the solution.
Upvotes: 0
Reputation: 308849
You have TEMPLATE_DIR
in your settings. It should be TEMPLATE_DIRS
.
Upvotes: 2
Reputation: 599600
I doubt your template directory is inside the static directory: remove that part of TEMPLATE_DIRS.
Upvotes: 0