Home > database >  Why am I getting this error when I try to switch HTML pages
Why am I getting this error when I try to switch HTML pages

Time:01-04

I made basic HTML/CSS files, that I'm trying to run through Django, but every time I run it and try to switch pages, I get this error:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/about.html
Using the URLconf defined in test.urls, Django tried these URL patterns, in this order:

admin/
[name='main']
add [name='about']
The current path, about.html, didn’t match any of these.

Here's what that my .urls file looks like:

from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('add',views.about,name='main.html'),
    path('add',views.about,name='about.html')
]

Here's my .views file looks like:

from django.shortcuts import render

def main(request):
    return render(request,'main.html')
def about(request):
    return render(request, 'about.html') 

Lastly Here's the section of my Settings file that I modified to find the file:

'DIRS': [os.path.join(BASE_DIR,'templates')],
    'APP_DIRS': True,

Is there something else I'm supposed to do to make this work?

CodePudding user response:

If you want to access about view, you should add this path to urlpatterns:

path('about/', views.about)

Then you can access it through /about/ URL not /about.html, the same as for main view.

CodePudding user response:

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')
]
  •  Tags:  
  • Related