templates django-error   5   6572
Solving Django Error: TemplateDoesNotExist at /app_name/


TemplateDoesNotExist at /app_name/

If you are facing above template error, there is a high possibility that at-least one of the below listed point applies to you.



1. Wrong template name:

Make sure when rendering the template, you are using right name of template. 

return render(request, 'app_name/tools.html', data)

Check if template name is actually tools or it is tool?



2. Wrong app name:

In the above render statement, confirm if the appname used is correct or not.

return render(request, 'app_name/tools.html', data)



3. Installed Apps:

Please confirm if your app is listed in installed apps in settings.py file.

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'your-app-here',
]



4. Template Directory Structure:

Make sure your templates are places inside a directory with same name as your app's name which in itself is inside templates directory. Confused? 

So your templates directory structure should be as below.

app_name
|
|-templates
|    |-app_name
|    |    |-tools.html



5. Where is Django looking for templates:

Confirm if Django is looking for templates in app directories. For this you need to see templates setting in settings.py file. Check if APP_DIR is set to True. If this is set to False, Django won't look for templates in app directories.

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',
],
},
},
]



6. Project level templates:

If you are using something like below in your project's urls.py file

urlpatterns += [
path(r'robots.txt/', TemplateView.as_view(template_name="project_name/robots.txt", content_type='text/plain')),
]


It could be any file instead of robots.txt, then make sure there is templates directory in root directory of project. This template directory is outside of every app. Directory structure would be as below.

|-project_name
|    |-templates
|    |    |-project_name
|    |    |    |-your-template-here


These template files are project level template files.

Also add 'DIRS': [os.path.join(BASE_DIR, 'templates')],  in TEMPLATES tuple in settings.py file. BASE_DIR is defined in settings.py file at the top. If not define as below.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


If you are still unable to resolve the error, feel free to comment or contact us or connect on facebook page.

Host your Django project for free.

templates django-error   5   6572

Related Articles:
Designing custom 404 and 500 error pages in Django
How to create your own awesome 404 error or 500 error page in django. Step by step guide to help you design your own 404 not found error page in Django. Design your own 500 internal server error page in Django application...
Django Template Fiddle Launched !!!!
Django template fiddle, Experimenting with Django templates, Playing with Django template, Django fiddle, template fiddle, djangotemplatefiddle.com,...
5 lesser used Django template tags
rarely used Django template tags, lesser-known Django template tags, 5 awesome Django template tags, Fun with Django template tags,...
Solving Django error 'NoReverseMatch at' URL with arguments '()' and keyword arguments '{}' not found.
Solving Django error 'NoReverseMatch at' URL with arguments '()' and keyword arguments '{}' not found, URL not found in Django, No reverse match in Django template error...

5 thoughts on 'Solving Django Error: Templatedoesnotexist At /App_Name/'
Lary :
This was very helpful. Thanks a lot.

Pahang Krisdyan :
I just relize that i haven't add my new app to installed app

Himanshu :
Thanks man

Renan Vieira Mechetti Ferreira :
What means abspach(__file__)?
Admin :
There is nothing like abspach. may be it is a typo. however there is something abspath. https://docs.python.org/2/library/os.path.html#os.path.abspath

Ashish Vyas :
STATIC_ROOT = os.path.join(BASE_DIR,'static')STATIC_URL = '/static/'STATICFILES_DIR = [ os.path.join(BASE_DIR,'course_project/static/')]i have this code in my django settings.py still i am getting the error 404 message

Leave a comment:


*All Fields are mandatory. **Email Id will not be published publicly.


SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.


Recent Posts:






© 2017-2019 Python Circle   Contact Us   Advertise with Us