Why am I getting this error when I try to switch HTML pages
So the problem is here you should add the name of the URL of the page as an example http://127.0.0.1:8000/home
PS - in urls.py
should write it like this home/
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('Here/main.html/',views.main,name='main.html'),
path('here/about.html/',views.about ,name='about.html')
]
UPDATE 05/01/2022
Follow these steps to get the same result
-
Run-on your terminal
django-admin startproject Tuto
anddjango-admin startapp tutoApp
like you're did in this project. -
Go to
settings.py
and add your app toINSTALLED_APPS
-
Create a folder on your TutoApp and name it
templates
and create the following fileindex.html
,about.html
. -
Go to
settings.py
import os
and on TEMPLATES change'DIRS': []
with'DIRS': [os.path.join(BASE_DIR),'templates']
-
You need to add some functions to your
views.py
from django.shortcuts import render
def homepage(request):
return render(request, 'index.html')
def about(request):
return render(request, 'about.html')
- In /tuto/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('tutoApp.urls'))
]
- Back to you're app and create a file name
urls.py
from . import views
from django.urls import path
urlpatterns = [
path('home/', views.homepage),
path('about/', views.about)
]
add some HTML to these pages to recognize which page you're on.
- Run
python3 manage.py runserver
and go to Home Page About page