Django Rest - TemplateDoesNotExist: How to solve it?

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

 

Before anyone asks, I've checked a lot of answers, and 'rest_framework' is listed on my Installed Apps. I have created a new venv and installed all dependencies on it again and still the same error.
When I try the url http://127.0.0.1:8000/admin I get the error template TemplateDoesNotExist at /Admin. When I try any endpoint of my API I get the same error.

I'm a bit confused because this project was running on my computer 1 month ago, but I got a problem in my computer and had to format. When I cloned the project again, got this error.

I'm going to list some of my settings about directory folder, I'm having a bad feeling about it.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'build')],
        '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',
            ],
        },
    },
]

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'build/static'),
]

Folders structure is:

Appapi/
   movies/
     settings.py
     urls.py
     wsgi.py
   imdb/
     migrations/
          migrationsfiles....
     models.py
     views.py
     serializers.py
     ...
   venv/
manage.py
README.md
requirements.txt

And some other files, like gitignore, procfile, etc.

Some of the errors traceback: django.template.exceptions.TemplateDoesNotExist: index.html

line 47, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)  

Edit:
Django version 2.1;
I don't have a templates directory, I'm using rest-framework to make an API, so I'm not dealing with html, css and js with Django.

profilepic.png
manpreet 2 years ago

 

Can you share the place of the template directory. if the templates directory in the Appapi/ or in each app's directory.

Django Version ?

I have suggest some changes in settings.py file.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

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

add a directory templates in every app

Appapi/
   movies/
     settings.py
     urls.py
     wsgi.py
   imdb/
     templates/
     migrations/
          migrationsfiles....
     models.py
     views.py
     serializers.py
     ...
   venv/
manage.py
README.md
requirements.txt

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.