Home > Enterprise >  How to fix TemplateDoesNotExist Error on Windows10?
How to fix TemplateDoesNotExist Error on Windows10?

Time:10-28

I have been following the tutorial for [Writing your first Django app][1]

In part 3, I was trying to use a template. I am working with Python 3.1, Django 3.2 on a Windows10.

Below is the error that I get:

  Django tried loading these templates, in this order:

  Using engine django:

   - django.template.loaders.app_directories.Loader: 

      C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\templates\polls\index.html (Source does not exist)

   - django.template.loaders.app_directories.Loader: 

      C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\templates\polls\index.html (Source does not exist)

Below is my file structure:

mysite
 -- mysite
|    --settings.py
|    --other files
 -- polls
|    --templates
|   |    --polls
|   |   |   --index.html
|    --views.py
|    --other files
 -- db.sqlite3
 -- manage.py`

I added a reference to polls configuration class in the INSTALLED_APPS setting.

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Any help would be appreciated.

CodePudding user response:

You might have to indicate to django where to find your templates, put this (somewhere around line 60) in settings.py

# settings.py
TEMPLATES = [
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
]
  • Related