Home > Mobile >  This engine did not provide a list of tried templates
This engine did not provide a list of tried templates

Time:10-05

Wup, I'm trying to deploy a localhost web using Django but I get the following error:

TemplateDoesNotExist at /
templates/index.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 4.1.2
Exception Type: TemplateDoesNotExist

I was looking tutorials and docs but I didn't found the answer.

Here is my settings.py

ALLOWED_HOSTS = ['*']
DEBUG = True
ROOT_URLCONF = 'FortyTwop.urls'
SECRET_KEY = 'This is a secret key'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["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',
            ],
        },
    },
]

also urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index')
]

And views.py

from email import message
from http.client import HTTPResponse
from django.shortcuts import render

# Create your views here.

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

My path tree:

.
├── FortyTwop
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── templates
│   │   └── index.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── manage.py

What Im doing bad or what I didn't have in the settings?, this project is just for test.

CodePudding user response:

templates/ is the base path you've configured in the settings, so you'll want

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

Furthermore, TEMPLATE_DIRS hasn't been a thing since Django 1.8 or so, and you're on Django 4.x. See these instructions.

  • Related