I was using django 2.0 ,my templates were working fine ,but now i changed the version to 3.0 , it is giving error Template does not exist
My views.py:-
from django.shortcuts import render
from testApp.models import Employee
from django.http import HttpResponse
# Create your views here.
def empinfo(request):
emp_list=Employee.objects.all()
my_dict={'emp_list':emp_list}
return render(request,'testApp/emp.html',context=my_dict)
emp.html:
<!DOCTYPE html>
{%load static}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{%static "css/demo3.css"%}">
<title></title>
</head>
<body>
<h1>This is sample response</h1>
</body>
</html>
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'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',
],
},
},
]
traceback:-
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\DJANGOPROJECT\EMPproject\testApp\views.py", line 8, in empinfo
return render(request,'testApp/emp.html',context=my_dict)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: testApp/emp.html
[05/May/2021 14:36:57] "GET /empinfo/ HTTP/1.1" 500 81956
Not Found: /favicon.ico
[05/May/2021 14:36:58] "GET /favicon.ico HTTP/1.1" 404 2084
and i have added template_dir in DIRS
Please help me in resolving this error