Django Templatedoesnotexist

Django TemplateDoesNotExist?

First solution:

These settings

TEMPLATE_DIRS = (
os.path.join(SETTINGS_PATH, 'templates'),
)

mean that Django will look at the templates from templates/ directory under your project.

Assuming your Django project is located at /usr/lib/python2.5/site-packages/projectname/ then with your settings django will look for the templates under /usr/lib/python2.5/site-packages/projectname/templates/

So in that case we want to move our templates to be structured like this:

/usr/lib/python2.5/site-packages/projectname/templates/template1.html
/usr/lib/python2.5/site-packages/projectname/templates/template2.html
/usr/lib/python2.5/site-packages/projectname/templates/template3.html

Second solution:

If that still doesn't work and assuming that you have the apps configured in settings.py like this:

INSTALLED_APPS = (
'appname1',
'appname2',
'appname3',
)

By default Django will load the templates under templates/ directory under every installed apps. So with your directory structure, we want to move our templates to be like this:

/usr/lib/python2.5/site-packages/projectname/appname1/templates/template1.html
/usr/lib/python2.5/site-packages/projectname/appname2/templates/template2.html
/usr/lib/python2.5/site-packages/projectname/appname3/templates/template3.html

SETTINGS_PATH may not be defined by default. In which case, you will want to define it (in settings.py):

import os
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))

Django TemplateDoesNotExist at templates

Don't put your templates in landingpage folder. You should put your Templates in your app forms

Try to use this :-

Make a new folder in forms named templates and then make a new folder in templates named forms.

Your structure of folders should be like this :-

forms -> templates -> forms -> index.html

Use this in your views.py :-

def index(request):
return render(request, 'forms/index.html')

Django Exception: 'TemplateDoesNotExist at /'

Your TEMPLATES setting is as follows (truncated to keep answer short):

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
...
},
]

The problem here is that the DIRS part is just an empty list. By default Django will search all the directories in DIRS for templates and if APP_DIRS is True it will also search the sub-directory templates in each of the apps present in INSTALLED_APPS. You need to add your directory to the DIRS list. Modify the setting as so:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'], # Add templates directory to the list
'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',
],
},
},
]

Django - templatedoesnotexist

I had the same problem saying template does not exist and I solved it by changing the URL pattern in my views.py where previously I had mentioned just date.html, later I edited with blog/date.html. Hope it might help you.

How to solve django TemplateDoesNotExist

There's no need to define additional template directories in the Django settings. All registered apps (apps that are in your INSTALLED_APPS list in settings.py) use a default templates directory my-app-directory/templates/.

Inside your app directory, create a folder called templates (all lowercase), place your templates inside this folder. So if you had an app called blog it would look something like this:

> blog/
> migrations/
> 0001_initial.py
> templates/
> my_template.html
> admin.py
> apps.py
> models.py
> views.py
> mysite/
> settings.py
> urls.py
> wsgi.py
> manage.py

You can then use your my_template.html template in a view like this:

def my_view(request):
context = {}
return render(request,'my_template.html', context)

Note, we reference the template as if we are inside the templates/ directory

how to fix template does not exist in Django?

It seems that you render the template with Blog/index, but you need to specify the entire file name, so Blog/index.html and without a leading (or trailing) space:

def html(request):
return render(request, 'Blog/index.html')

what is the exception: TemplateDoesNotExist at /myapp/form in Django project

in your views, remove template/ from the return so it is just return render(request, 'forms.html')

Django will know where to find the templates.



Related Topics



Leave a reply



Submit