Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Django Rest - TemplateDoesNotExist: How to solve it?

General Tech Bugs & Fixes
Max. 2000 characters
Replies

usr_profile.png
Sarah Jones

User

( 8 months 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.

usr_profile.png
Yasmin Mirza

User

( 8 months 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

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif