Template Does not exist
For Django 1.8 or above
you need to open the settings.py
file and add the template path in the DIRS
key of TEMPLATES
list as a list of string.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['Secondjango/Secondjango/templates/welcome'], # <<<<<<<<Here
'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',
],
},
},
]
Thanks.
Try this:
In your settings.py file replace
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
with
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
os.path.join(PROJECT_DIR, 'templates/welcome')
)
Then, in your code, just call render_to_response("home.html")
That should resolve your issue.
For Django 1.8 or above just Add the following in TEMPLATES DIR variable list in settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'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',
],
},
},
]
This property points to template directory 'DIRS': ['templates'],
This error may arises due to the incorrect template directories
Try some change on settings.py
as below
import os.path
Temp_Path = os.path.realpath('.')
...
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
...
TEMPLATE_DIRS = (
Temp_Path +"/template"
)
Then put all your template inside template folder and css/javascript file in static folder which is located inside your application folder. Hope this will solve your problem.
My suggestion don't put template folder inside application folder
Django will choose the first template it finds whose name matches, and if you had a template with the same name in a different application, Django would be unable to distinguish between them. We need to be able to point Django at the right one, and the easiest way to ensure this is by namespacing them. That is, by putting those templates inside another directory named for the application itself.