Home > OS >  TemplateDoesNotExist at / Home.html Exception Type: TemplateDoesNotExist
TemplateDoesNotExist at / Home.html Exception Type: TemplateDoesNotExist

Time:12-07

  1. My Customers urls.py

''' from django import urls from django.urls import path from django.urls.resolvers import URLPattern from . import views

urlpatterns = [
    path('', views.Home ,name= 'Home'),
    path('Hall/', views.Hall ,name= 'Hall'),
    path('Food_item/', views.Food_item ,name= 'food'),
    path('About_us/', views.About_us ,name= 'about'), 
]
'''
  1. My Web_project urls.py

              '''
    
         from django.contrib import admin
         from django.urls import path, include
    
        urlpatterns = [
       path('admin/', admin.site.urls),
       path('', include('customer.urls')),
      ]
    
              '''
    
  2. Settings.py Templates

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

    ]

  3. Customers View.py

       '''
    

    from django.http.response import JsonResponse from django.shortcuts import render

     def Home(request):
         return render(request, "Home.html", {"title":" Home"})
    
     def Hall(request):
         return render(request, "Hall.html", {"title": "Hall"})
    
     def Food_item(request):
         return render(request, "Food_item.html", {"title": "Food_item"})
    
     def About_us(request):
         return render(request, "About_us.html", {"title": "About_us"})
    
         '''
    
  4. My cd is web_project>customer>templates>customer>Home.html

  5. The error it showing

     '''
    
     Template-loader postmortem
     Django tried loading these templates, in this order:
    
     Using engine django:
    
      django.template.loaders.filesystem.Loader: C:\Users\Nawaf 
      Bhatti\Desktop\New\web_project\templates\Home.html (Source does not exist)
      django.template.loaders.app_directories.Loader: C:\Users\Nawaf 
      Bhatti\Desktop\New\env\lib\site-packages\rest_framework\templates\Home.html 
      (Source does not exist)
     django.template.loaders.app_directories.Loader: C:\Users\Nawaf 
     Bhatti\Desktop\New\env\lib\site- 
     packages\django\contrib\admin\templates\Home.html (Source does not exist)
     django.template.loaders.app_directories.Loader: C:\Users\Nawaf 
     Bhatti\Desktop\New\env\lib\site- 
     packages\django\contrib\auth\templates\Home.html 
    (Source does not exist)
     django.template.loaders.app_directories.Loader: C:\Users\Nawaf 
     Bhatti\Desktop\New\web_project\customer\templates\Home.html
    (Source does not exist)
    
     '''
    

CodePudding user response:

Try adding the path from the templates/ subfolder like so:

def Home(request):
    return render(request, "customer/Home.html", {"title":" Home"})
  • Related