I know there are many questions similar to this one, but none has solved my problem yet.
Python version: 3.4 Django version: 1.8
I get TemplateDoesNotExist at /lfstd/ when loading http://127.0.0.1:8000/lfstd/.
system.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
lfstd/views.py:
def index(request):
[...]
return render(request, 'lfstd/index.html', context_dict)
project urls.py:
from django.conf.urls import include, url
from django.contrib import admin
url(r'^admin/', include(admin.site.urls)),
url(r'^lfstd/', include('lfstd.urls')),
lfstd urls.py:
from django.conf.urls import patterns, url
from lfstd import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'))
Running print on base_dir and template_path, I get:
Base dir: C:\Users\Phil\PycharmProjects\TownBuddies
Template path: C:\Users\Phil\PycharmProjects\TownBuddies\templates
Which is exactly where my project and template folder is located. However, django doesn't look in that folder for templates. It looks in the following folders:
C:\Python34\lib\site-packages\django\contrib\admin\templates\lfstd\index.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\auth\templates\lfstd\index.html (File does not exist)
In fact, if I move my template there, it does find it and it works.
Any help is very appreciated, I'm starting out with Django and completely stuck...
EDIT:
I changed TEMPLATE_DIRS to TEMPLATES but Django still isn't looking in the templates folder:
TEMPLATE_DIRS
setting is deprecated in django 1.8. You should use the TEMPLATES
instead:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_PATH],
'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',
],
},
},
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With