I included the path to my templates folder in the settings.py file by setting:
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
and likewise for STATIC_FILES_DIR, but I keep getting the TemplateDoesNotExist error. When I look at the postmortem of the error, I see:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
C:\Python27\lib\site-packages\django\contrib\admin\templates\home.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\auth\templates\home.html (File does not exist)
Why would the template.loader be looking for the template files in that directory instead of the one specified in my settings.py file? Also, when I copy over my home.html page into the first directory mentioned in the error message, the page loads the content without error, so how can I get the loader to move from the location that it's searching to the directory where the files are actually located?
Valid setting name is TEMPLATE_DIRS and it is a tuple of strings, not the simple string:
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'), )
Related
trying to deploy my app to uwsgi server
my settings file:
STATIC_ROOT = "/home/root/djangoApp/staticRoot/"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/home/root/djangoApp/static/',
]
and url file:
urlpatterns = [
#urls
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
and if I try to execute the command:
python manage.py collectstatic
Then some files are okay ( admin files ), but I see an error next to files from static folder. The error is like:
Found another file with the destination path 'js/bootstrap.min.js'. It
will be ignored since only the first encountered file is collected. If
this is not what you want, make sure every static file has a unique
path.
and have no idea what can I do to solve it.
Thanks in advance,
The two paths you have in STATICFILES_DIRS are the same. So Django copies the files from one of them, then goes on to the second and tries to copy them again, only to see the files already exist.
Remove one of those entries, preferably the second.
do you have more than one application?
If so, you should put any file on a subdirectory with a unique name (like the app name for example).
collectstatic collects files from all the /static/ subdirectories, and if there is a duplication, it throw this error.
i'm new in python world and i'm using python 3.4 and django 1.7
When o put DEBUG=True in settings.py the browser shows me an error like:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
C:\workspace_virtualenv34\prog\prog\templates\main_sites\registration\login.html (File does not exist)
But my templates are in a different path:
C:\workspace_virtualenv34\prog\templates\
In settings.py i set ROOT_PATH as:
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname( file ), os.pardir))
Is there anyway to turn back path levels that solve this problem?
Thanks.
You should be able to provide any directories to TEMPLATE_DIRS that django will use to search for templates
https://docs.djangoproject.com/en/1.8/ref/settings/#template-dirs
you should be able to construct this using the ROOT_PATH to avoid referencing absolute paths directly; change for your specific path:
TEMPLATE_DIRS = (
os.path.join(ROOT_PATH, '..', '..', 'prog', 'templates'
)
I am trying to create a login page in my django application. I created a "templates" folder on the root directory of my application.
Then on my settings.py I wrote this code.
TEMPLATE_DIRS = (os.path.join(BASE_DIR,'templates'),)
And it is giving this feedback:
TemplateDoesNotExist at /login/
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:
/Users/julianasakae/Desktop/DjangoProject/demo/lib/python3.4/site-packages/django/contrib/admin/templates/login.html (File does not exist)
/Users/julianasakae/Desktop/DjangoProject/demo/lib/python3.4/site-packages/django/contrib/auth/templates/login.html (File does not exist)
/Users/julianasakae/Desktop/DjangoProject/boardgames/main/templates/login.html (File does not exist)
I tryed everything, it does not seems to work.
Any suggestions?
What version of Django are you using? It appears that TEMPLATE_DIRS was used prior to 1.8 but in the current version it has changed to a DIRS option in the TEMPLATES setting.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'/home/html/templates/lawrence.com',
'/home/html/templates/default',
],
},
]
Template DIRS Option Docs
Well it is not a good solution, but try hardcoding the full path.
I'm trying to deploy django project to webfaction and stuck with the problem that the server does not see my templates folder
PROJECT_DIR = os.path.dirname((os.path.dirname((os.path.dirname(__file__)))))
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR,'templates'),
)
python path in httpd.conf :
python-path=/home/wadadaaa/webapps/promo_site/myproject:/home/wadadaaa/webapps/promo_site/lib/python2.7
And i have exception:
Exception Type: TemplateDoesNotExist
Exception Value: index.html
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/wadadaaa/webapps/promo_site/templates/index.html (File does not exist)
any ideas how to fix it?
When deploying to WebFaction I add the project's parent directory to the python_path:
python-path=/home/wadadaaa/webapps/promo_site:/home/wadadaaa/webapps/promo_site/myproject:/home/wadadaaa/webapps/promo_site/lib/python2.7
If you're using Django 1.5.x, a common way I "map" directory paths like TEMPLATE_DIRS, STATIC_ROOT, etc, is to use a function to compute those. This is especially useful if you work on more than one machine, or in a group, where the path to these files is going to vary per-developer:
# settings.py
import os
def map_path(directory_name):
return os.path.join(os.path.dirname(__file__),
'../' + directory_name).replace('\\', '/')
...
TEMPLATE_DIRS = (
map_path('templates'),
)
This is a convenient way to map your templates directory, given a project structure of:
my_app/
my_app/
__init__.py
settings.py
...
a_module/
__init__.py
models.py
templates/
layouts/
base.html
index.html
...
I am trying to load a register template for my first django site,
I put register.html file in /home/Desktop/projects/purple/purple/templates/registration.html
here but there is a error that is say to there is no file I did not understant that's why? can anyone have a idea?
Request Method: GET
Request URL: http...:127.0.0.1:8000/registration/
Django Version: 1.4
Exception Type: TemplateDoesNotExist
Exception Value: registration.html
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/Desktop/projects/purple/purple/templates/registration.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/registration.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/registration.html (File does not exist)
Using loader django.template.loaders.eggs.Loader:
Given that the exception copy and pasted refers to:
/home/Desktop/projects/purple/purple/templates/registration.html
and can't find it... all of your problems lie in whether or not registration.html exists at the directory.
There are 2 possibilities:
File doesn't exist
cd into that exact directory and find out if it does.
Permissions
ls -lh /home/Desktop/projects/purple/purple/templates/registration.html
Make sure it's readable.
chmod 644 /home/Desktop/projects/purple/purple/templates/registration.html
do you have Registration directory inside Template directory??
if so then include this is your settings.py .
TEMPLATE_DIRS = (
BASE_DIR +'/Templates',
BASE_DIR +'/registration',
)
Because django is looking for registration.html in your Template directory instead of /template/registration.
see the order you mentioned in the question. watch the path.