I have some third-part library, templates from that library is diplayed by default.
I want to replace layout template, from which all other start inheritance.
So, in my local app I create new layout.html file, which contents
{% extends 'library:layout.html' %}
But in that case I've got
TemplateDoesNotExist at /test-url/
test.html
But still Template-loader postmortem display, that it can find file:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/path/to/app/templates/test.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/path/to/library/app1/templates/test.html (File does not exist)
/path/to/library/app2/templates/test.html (File does not exist)
/path/to/library/app3/templates/test.html (File exists)
So, in library app3 Django found template, but for some reason do not use it. Can you help with this issue?
Thanks.
Make sure that there isn't another missing template that is causing the error.
Your extends tag looks wrong. I would expect to see library/layout.html, not library:layout.html
{% extends 'library/layout.html' %}
Related
The server is working fine, however while using extend for this 'home.html' file unable to link the template :
In 'home.html':
{ % extends "/template1/personal/header.html" % }
While loading localhost:
Django tried loading these templates, in this order:
`Using engine django:
django.template.loaders.app_directories.Loader: /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/ffgg/home.html (Source does not exist).
django.template.loaders.app_directories.Loader: /usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/ffgg/home.html (Source does not exist)`
1) Check what is in TEMPLATE_DIRS Variable in settings.py. That is the folder Django looks up in every app in order to find your template.
2) Try remove the leading slash:
{% extends 'template1/personal/header.html' %}
3) if template1 is in TEMPLATE_DIRS, then 'app/template.html' would be enough
{% extends 'personal/header.html' %}
Read on:
https://tutorial.djangogirls.org/en/template_extending/
https://docs.djangoproject.com/en/1.7/topics/templates/
I am having a strange issue using the built in password_rest view of django(1.8). In the documentation they say that the template name defaults to registration/password_reset_form.html. Keeping that in mind, I didn't give any template name in my urls.py, thinking that django will load the default template.Here is my url for the password reset
urls.py
url(r'^password_reset$', auth_views.password_reset, name='password_reset'),
When I click the forgot password link,
<p><a href={% url 'password_reset' %}> Forgot your password?</a></p>
which executes the password_rest view, I am getting Template DoesNotExist error and below is the error message
TemplateDoesNotExist at /accounts/password_reset
registration/password_reset.html
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/vinothkumar/github/djtest/templates/registration/password_reset.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/home/vinothkumar/github/djtest/venv_new/lib/python3.4/site-packages/django/contrib/admin/templates/registration/password_reset.html (File does not exist)
/home/vinothkumar/github/djtest/venv_new/lib/python3.4/site-packages/django/contrib/auth/templates/registration/password_reset.html (File does not exist)
/home/vinothkumar/github/djtest/accounts/templates/registration/password_reset.html (File does not exist)
my question is why the template loader is looking for /registration/password_reset.html instead of loading the default /registration/password_reset_form.html?
I tried the same approach for password_reset_done, in this case it loads the default template /registration/password_reset_done.html. and everything there works fine.
So I changed the name of my registration template from user_form.html to register.html. I've also changed it in the urls.py file to reflect the new name, however when I try to go to the register page I get the following:
Exception Type: TemplateDoesNotExist
Exception Value:web/user_form.html
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:
../swl/root/lib/pythpy2.7.egg/django/contrib/admin/templates/web/user_form.html (File does not exist)
../django/contrib/auth/templates/web/user_form.html (File does not exist)
../templates/web/user_form.html (File does not exist)
..tastypie/templates/web/user_form.html (File does not exist)
../bootstrap3/templates/web/user_form.html (File does not exist)
../web/templates/web/user_form.html (File does not exist)
Why would the template loader still be looking for the old filename?
edit: this is my url for register:
url(r'register/?$',
UserCreate.as_view(),
{
'template_name':'accounts/register.html'
},
name = 'register'),
Try to replace all user_form.html to registration.html in all files. You can use Find/replace in files feature (or something similar) of your text editor or IDE.
Change url to:
url(r'register/?$',
UserCreate.as_view(template_name='accounts/register.html'),
name = 'register')
The class-based views will attempt to use a default template name when no name is explicitly declared. (The CreateView uses (appname)/(model)_form.html) Your choices are:
Name your template using the default name
Specify the template in the URL (as in Vladimir's answer)
Specify the template name in the view code like so:
class UserCreate(CreateView):
template_name = "accounts/register.html"
Hope this helps
Restart the apache server.
For Ubuntu server 20:
/etc/init.d/apache2 restart
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.
Originally I had just one app in my Django project, the templates consisted of an index.html a detail.html and a layout.html ... the index and detail files extended the layout. They all lived in the same directory ([app1]/templates/[app1]/) and it could find all the files fine.
Now I've got a second app, and I want to re-use the layout.html ... I decided to make a templates dir off the base of the django project, and put it in there. Here's what my directory structure looks like now:
<basepath>/<django_project>/templates/shared
<basepath>/<django_project>/<app1>/templates/<app1>
<basepath>/<django_project>/<app2>/templates/<app2>
I updated my settings.py:
TEMPLATE_DIRS = (
'/full/path/to/<django_project>/<app1>/templates',
'/full/path/to/<django_project>/<app2>/templates',
'/full/path/to/<django_project>/templates',
)
In the 'shared' dir I have the layout.html ... from the app1 or app2 template dirs, I have the index.html and the 'extends' line at the top of the file reads:
{% extends "shared/layout.html" %}
However, when I try to load the apps view, it gets an error that it can't find shared/layout.html
TemplateSyntaxError at /
Caught TemplateDoesNotExist while rendering: shared/layout.html
Any ideas what I'm missing? This should be fairly straightforward, I must be overlooking something really obvious?
My bad! I thought I was running this behind Nginx, so I restarted that and was still having the problems. After re-checking I realized I was running behind Apache, restarting Apache updated my TEMPLATE_DIRS and now it works!