TemplateDoesNotExist at /rango/ - django

I have tried my best to source and to fix this problem, but I can't seem to find the answer.
Currently going through the tangowithdjango tutorial, I'm currently on 5. Templates and Static Media.
http://www.tangowithdjango.com/book17/chapters/templates_static.html
Trying to get my site to show its first template, but just before I reach 5.2 I tried loading my site and got this error message:
TemplateDoesNotExist at /rango/
rango/index.html
Request Method: GET
Request URL: http://127.0.0.1:8000/rango/
Django Version: 1.8
Exception Type: TemplateDoesNotExist
Exception Value:rango/index.html
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib
/python2.7/site-packages/django/template/loader.py in get_template, line 46
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7
/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.9
Here is my settings.py file:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
# Template from tangowithdjango 5.1: Templates and Static Media
#
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
TEMPLATE_PATH,
)
Here is my views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
# Construct a dictionary to pass to the template engine as its context.
# Note the key boldmessage is the same as {{ boldmessage }} in the template!
context_dict = {'boldmessage': "I am bold font from the context"}
# Return a rendered response to send to the client.
# We make use of the shortcut function to make our lives easier.
# Note that the first parameter is the template we wish to use.
return render(request, 'rango/index.html', context_dict)
Sorry about the comments, after a few tries I copied the site's code, but still to no success.
My file structure is as follows:
workspace
tango_with_django_project
manage.py
tango_with_django_project
settings.py
templates
rango
index.html
To add, here is what is shown at 127.0.0.1:8000/rango :
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/site-packages/django/contrib/admin/templates/rango/index.html (File does not exist)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/site-packages/django/contrib/auth/templates/rango/index.html (File does not exist)

TEMPLATE_DIRS is deprecated in django 1.8. You should use the TEMPLATES setting instead. Chances are that you already have the TEMPLATES variable in the settings.py so alter the DIRS key like this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_PATH], # <-- 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',
],
},
},
]

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
Add this below BASE_DIR:
PROJECT_PATH = os.path.join(BASE_DIR, os.pardir)
Next following should look like this:
STATIC_PATH = os.path.join(PROJECT_PATH, 'tango_with_django_project/static')
STATIC_URL = '/static/'
STATICFILES_DIRS =(
STATIC_PATH,
)
TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'tango_with_django_project/templates')
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'tango_with_django_project/media')

Your directory structure is wrong. check out what this code is doing...
directory = os.path.dirname(os.path.abspath(__file__))
according to your directory structure this code returns...
/root_path/tango_with_django_project/tango_with_django_project
therefore according to your structure, templates folder is not inside the folder tango_with_django_project which is where it thinks it should be.
you could just specify a direct path to your templates if you want.
TEMPLATE_PATH = '/root_project/tango_with_django_project/templates/'
On a side note, Tango with Django is the worst name for a tutorial series, possibly ever.

Related

Jinja2 throwing templatedoesnotexist error in Django project

I'm trying to use jinja2 in my Django project (ver 1.10). After setting it up, once I try to run the project, I get TemplateDoesNotExist at /base/index.html and
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine jinja2:
This engine did not provide a list of tried templates.
In templates folder, I have a base directory where index.html is placed. Moreover, if I use Django's template engine, this same folder structure works perfectly. How can I fix this issue?
My config is as follows:
In settings.py (note that I've deliberately excluded the Django template fallback):
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {'environment': 'uberfordoc.jinja2.environment',
},
},
]
I also have a file called jinja2.py kept in the project folder:
from __future__ import absolute_import
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.urlresolvers import reverse
from jinja2 import Environment
def environment(**options):
env = Environment(**options)
env.globals.update({
'static': staticfiles_storage.url,
'url': reverse,
})
return env
This was my BASE_DIR and MAIN_DIR in settings.py
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MAIN_DIR = os.path.dirname(os.path.dirname(__file__))
and my jinja2 templates were at the path
/Users/username/Desktop/uberfordoc/templates/jinja2
changed
'DIRS': [os.path.join(BASE_DIR, 'templates')],
to
'DIRS': [os.path.join(MAIN_DIR, 'templates/jinja2')],
and it worked. Got the hint thanks to #Timbadu by printing
print os.path.join(BASE_DIR, 'templates')

TEMPLATE_DIRS is missing in settings.py (django 1.6)

I am reading http://www.djangobook.com/en/2.0/chapter04.html which follows Django 1.4 but I use Django 1.6 so how to set the template directory in Django 1.6 as settings.py doesn’t have TEMPLATE_DIRS variable and why the developers changed this?
Thanks in advance.
Add to settings.py
from os.path import join
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
Add this to settings.py. In django 1.6 BASE_DIR is defined. Otherwise define BASE_DIR as
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
According to Django tutorial, you should add
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
to your settings.py file (so it is a list not a tuple)
It should be
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
Or you might see an error like this :
DeprecationWarning: The TEMPLATE_DIRS setting must be a tuple. Please
fix your settings, as auto-correction is now deprecated.
self._wrapped = Settings(settings_module)
For django >= 1.6 it is a tuple
Use the below given code snippet. Paste it in last of the settings.py file.
from os.path import join
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
Here BASE_DIR means your project directory, not the inner directory where the settings.py resides. Create a directory named "templates" (without quotes) inside the BASE_DIR and store your templates inside that directory. Django will join templates directory to the BASE_DIR using os.path.join() function. Hope this helps.
As I posted https://stackoverflow.com/a/40145444/6333418 you have to add it to the DIR list that is inside settings.py under TEMPLATES.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['[project name]/templates'], # Replace with your project name
'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',
],
},
},
]

Template does not exist

I am new to Django. I made a folder named templates in my project and "base.html" inside it, it works fine. But when I make new folder inside templates welcome and then "home.html" and I write some lines of code in my views.py file as
from django.shortcuts import render_to_response
def hello(request):
return render_to_response('welcome/home.html')
and settings.py includes
# Django settings for Telecom project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
import os
#BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_DIR = os.path.dirname(__file__)
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mysql', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'UTC'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = 'http://localhost:8000/media/admin/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'b9_hyqe*b&ra_&wlm5a9xas_ag#5mjv-dy=to%hdk_u-#xvn*l'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
print PROJECT_DIR
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'Telecom.urls'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'welcome',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
but the error shows
TemplateDoesNotExist at /hello/
/welcome/home.html
Request Method: GET
Request URL: http://localhost:8000/hello/
Django Version: 1.6
Exception Type: TemplateDoesNotExist
Exception Value:
/welcome/home.html
Exception Location: C:\Python27\django\template\loader.py in find_template, line 131
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
Python Path:
['D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\Telecom',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.35-py2.7.egg',
'D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\Telecom',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Windows\\SYSTEM32\\python27.zip']
Server time: Tue, 18 Jun 2013 17:09:07 +0545
How can I solve it ?
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.
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.
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'],
For Django 2.0, I edited the value DIRS of TEMPLATES in setting file to the entry directory of the project:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['.'], # here set DIRS to project's entry directory
'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',
],
},
},
]
and the problem solved on both Mac and Windows systems.
You can use:
in settigns.py
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'),)
STATICFILES_DIRS = (
'static',
)
Please check if you have added your new application in the settings.py file under INSTALLED_APPS
Django compiles all the 'templates' folder from all the applications inside your project into a single 'templates' folder.
Please remember to create separate directory inside your applications 'template' folder to make it easier for the Django framework to find the template you are looking for.
suppose that you hace a django project "my_project", and the application "app_1" and "app_2"
my_project
-- my_project
-- manage.py
welcome
-- __init__.py
templates
-- home.html
-- models.py
-- views.py
app_1
-- __init__.py
templates
welcome
-- home.html
-- models.py
-- views.py
app_2
templates
a_subfolder
-- home.html
-- __init__.py
-- models.py
-- views.py
now, if you have some settings like.
#...
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
#...
INSTALLED_APPS = (
'app_2',
'app_1',
'welcome',
#...
)
#...
django will do that:
When you call render_to_response('welcome/home.html') (I think that some params are missing), django will look at "home.html" file in some some "welcome" folder in ALL aplications (in this case "app_1" and "app_2") that have a "templates" folder. (that is a convention)
EDIT
I have added you "welcome" app.
You have to call the method without app name render_to_response('home.html')
Check if there is any include tag in "hello.html" which has been given filepath that does not exist. The error raised comes up the same :-
TemplateDoesNotExist at /hello/
/welcome/home.html
Add template directory to your TEMPLATES in your project settings.py by 'DIRS': [os.path.join(BASE_DIR, 'templates')],
So the final TEMPLATES should be something like the following
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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',
],
},
},
]
Do this
-> Make sure your templates folder should be in root folder not in app folder
-> then goto your setting.py file and look for TEMPLATES = [ 'DIRS': ]
-> in DIRS put the path of your template folder like this 'DIRS':[r'path']
it will work
Another reason could be if the name of the folder in your app is template and not templates. Note 's' in the end.
Your settings.py file must be :
'DIRS': ["templates"]
Your templates folder must be under your main project name :
Like that
All I had to do was Install 'rest_framework' as one of the apps.
Have you created the file __init__.py inside your welcome folder?

Template Does not exist

I am new to Django. I use pydev eclipse as an IDE. First I created a project then an application welcome on that project. I made a folder named Templates within the project and make a file "home.html" and home.html contains
<div>
This is my first site
</div>
I modify the settings.py file as
TEMPLATE_DIRS = ("Templates")
INSTALLED_APPS = (
..........#all default items
'welcome', #the added one
)
views.py includes
from django.shortcuts import render_to_response
def home(request):
return render_to_response('home.html')
urls.py contains
from django.conf.urls import patterns, include, url
from welcome.views import home
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'MajorProject.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^home/$', home),
)
then I run it as django project and open my browser and see on localhost:8000/home
it shows error
TemplateDoesNotExist at /home/
home.html
Request Method: GET
Request URL: http://localhost:8000/home/
Django Version: 1.6
Exception Type: TemplateDoesNotExist
Exception Value:
home.html
Exception Location: C:\Python27\django\template\loader.py in find_template, line 131
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
Python Path:
['D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\MajorProject',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.35-py2.7.egg',
'D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\MajorProject',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Windows\\SYSTEM32\\python27.zip']
Server time: Sun, 2 Jun 2013 14:25:52 +0545
Try to set Templates Directory on setting.py.
as
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'templates'),
)
If you're using Django 1.8+
You'll get this warning:
(1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS, TEMPLATE_DEBUG.
Add your template directory to the Base TEMPLATES setting under the DIRS dictionary
Like so:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
root("templates"), #### 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',
],
},
},
]
in Django 1.9
in settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR+r'\templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
...
],
},
},
]
Directory with templates should be named templates, not Templates (even though on windows it may be the same). Also make sure, you have application in PYTHONPATH or the correct directory structure of your project and application like:
project/
project/
settings.py
...
welcome/
templates/
home.html
views.py
...
manage.py
Then you don't need to change TEMPLATE_DIRS because app_directories.Loader (enabled by default) will find the templates in your application.
Also of if you still want to change TEMPLATE_DIRS, use absolute paths, but preferred way is the app_directories.Loader.
check below steps to fix
step 1:
Inside templates, 'DIRS' : [ ], metion this:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
step 2:
Go in your views.py file and look for template_name (check its spelling and also check did you mentioned the right html file here or not)
step 3:
Check in your urls.py file wether you mentioned the right template name or not in the path
format: urlpatterns = [ path(" ", class name or function name, name = template name)
BASE_DIR = Path(file).resolve().parent.parent
This is default directory code by Django
And looks like this
C:\user\pc_name\django_project
But if you delete last .parent it will looks like this
C:\user\pc_name\django_project\django_project
So new BASE_DIR code which is this
BASE_DIR = Path(file).resolve().parent
Add this variable to TEMPLATE_DIR
TEMPLATE_DIR = os.path.join(BASE_DIR, 'template")
And last code define this
C:\user\pc_name\django_project\django_project\template
In the end safely uptade DIRS
'DIRS': 'TEMPLATE_DIR'
Hope you did

django override admin template

I am following part 2 of the Django tutorial. I am trying to override an admin template (base_site.html)
I copied the file from the django/contrib/admin/templates to mytemplates/admin/base_site.html
I also updated settings.py:
#Base Directory
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
#Template directories
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'mytemplates'),)
I tried putting the mytemplates folder in the root of the project folder as well as in the mysite folder with no luck. Any pointers would be great!
EDITED PREVIOUS USER RESPONSE -- THIS WORKS:
I think your relative path to the templates directory is wrong.
If you follow these steps it should work: (I tested it myself)
Put the mytemplates dir side by side with the manage.py file
project
-app1
-app2
-mytemplates
-admin
-base_site.html
-manage.py
Change the TEMPLATE_DIRS to:
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'mytemplates'),)
Make sure the order of the template loader is:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
#YardenST's answer almost worked for me. I guess it's a matter of configuration.
In case you run into trouble, I suggest you use this line:
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'mytemplates'),)
Next, put a breakpoint to show the actual outcome, or alternatively use print TEMPLATE_DIRS.
That's where you should place the templates you want to override.
#kat-russo, thx ;)
I tried to setup admin templates according to docs
project_name
-app1
-app2
-project_name //main folder -> settings.py , urls.py, wsgi.py
-templates
-admin
-project_name
base.html
without success, but
-templates
-admin
base.html
works for me.
my config (Django 1.10.4 w/Django CMS 3.4.1)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "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',
'sekizai.context_processors.sekizai',
'cms.context_processors.cms_settings',
],
},
},
]
You can override all templates.
Create an admin directory in templates and add the files.
The all files.
https://github.com/django/django/tree/master/django/contrib/admin/templates/admin