So , this is my first ever try with django and im currently learning about urls and views, ive been encountering the error that says "template not found " i apologize beforehand if the question is noob-ish. (here is the code for urls.py file)
`"""
URL configuration for views_urls project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home)
]
`
(below is the code for the view.py file that i created , which exists in the same folder as the url.py file)
`from django.shortcuts import render
def home(request):
return render(request, 'main.html')`
(below is the main.html file the exists in a folder called templates)
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>main</title>
</head>
<body>
<h1>The main html page is working </h1>
</body>
</html>`
(below are the changes i made in the settings.py)
`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',
],
},
},
]`
ps. ive made sure the spellings are all correct. i am still recieveing an error that says TemplateDoesNotExist at / main.html
kindly help, thank you.
What i was expecting was the contents of my main.html file to be displayed , but i got an error that saying template does not exist. Ive tried rechecking if django was successfully installed and it was.
Help would be greatly appreciated.