Home > Software engineering >  django.template.exceptions.TemplateDoesNotExist: customer/base.html
django.template.exceptions.TemplateDoesNotExist: customer/base.html

Time:11-28

  1. My customers urls.py
'''
    urlpatterns = [
        path('', views.base ,name= 'customer-base'),
        path('Hall/', views.Hall ,name= 'customer-Hall'),
        path('Food_item/', views.Food_item ,name= 'customer-food'),
        path('About_us/', views.About_us ,name= 'customer-about'), 
    ]
    '''
  1. My Web_project urls.py
'''
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('customer.urls')),
]
'''
  1. My views.py

'''

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

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

def Food_item(request):
    return render(request, "customer/Food_item.html", {"title":"Food"})

def About_us(request):
    return render(request, "customer/About_us.html", {"title":"About"})   

'''

I have tried everything but did not work for me.

CodePudding user response:

Check in your settings.py that this line you have configured or not

TEMPLATES = [
   {
     ....
     'DIRS': [BASE_DIR / 'templates'],
   }
]

CodePudding user response:

Your problem is not exactly defined. But the problem is in the placement of your templates folder. In settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR /  'templates'], # adding templates folder to base directory of each app
        'APP_DIRS': True,
        'OPTIONS': {
            # ... some options here ...
        },
    },
]

If You have an app called Customer then inside the app there's the templates directory then in views

def Hall(request):
    return render(request, "Hall.html", {"title":"Hall"})

should get the Hall.html placed in the templates folder of the same app. Hope this helps you out

  • Related