Solution 1 :

if you create your index.html file on templates/index.html,then you can use this settings on your settings.py file:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        #  Add  'TEMPLATE_DIR' here
        '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',
            ],
        },
    },
]

then in your view you need to render that file:

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

Solution 2 :

You have to use a TemplateView. It is just a simple view that serve a template html.

from django.views.generic import TemplateView

class IndexView(TemplateView):
    template_name = "PATH_TO_INDEXHTML"

Just add an url in urls.py for serving this view and let’s go

from django.urls import path

from .views import IndexView

urlpatterns = [
    path('index', IndexView.as_view(),
]

More information about templateview: https://docs.djangoproject.com/fr/4.1/ref/class-based-views/base/#django.views.generic.base.TemplateView

Problem :

My index is loading well on browser, but when I click home page, there is nothing 404 error, is responding static/index.html, (when I click home page or any other such as contact, it is searching for html in static) why is it asking for index.html in static files and how can I rectify that?[When i click home there is an error message as on the image

I stored my html files on templates folder thinking that when i clicked my dropdown, they were going to apper on my web.

Comments

Comment posted by D.L

you want a web page without creating a page ?

Comment posted by Peter

Am not very sure what you asked, but I have everything required such as html, static files and everything and my pages are present exactly like shown in the image above, unless am missing something am not aware of!

By