Home > Blockchain >  Page not found at /about/. The current path, about/, did not match any of these. Why can't djan
Page not found at /about/. The current path, about/, did not match any of these. Why can't djan

Time:02-12

I'm sure this question has been asked many times before but I'm sure I'm doing everything exactly as the tutorial says and it's still not working. I can access the home page just fine but not the about page.

Here is screenshot of the error:

https://i.stack.imgur.com/oFNAJ.png

I have the URL path in my .urls file (file below)

from django.urls import path
from . import views

urlpatterns = [
    path('', views.homepage, name='main-home'),
    path('about/', views.about, name='main-about'),
]

And in the .urls file I have referenced the .views file (below)

from django.shortcuts import render
from django.http import HttpResponse


def homepage(request):
    return HttpResponse('<h1>Home</h1>')


def about(request):
    return HttpResponse('<h1>About</h1>')

I could be missing something blatantly obvious but I've been staring at this for hours now and still can't figure out why it can't find the page.

EDIT: I am referring to the app urls file in the main post. In case its useful, here is the project .urls file:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('homepage/', include('home.urls')),
]

CodePudding user response:

Then prefixed your url with homepage as

localhost:8000/homepage/about/

It's always better to use {% url %} [Django-doc] template tags for urls inside templates which will point to your correct url even after you change url path but with the same name.

CodePudding user response:

Per your copied image, you're accessing localhost:8000/about, not loaclhost:8000/homepage/about, which I think if you were to visit right now would return your "about" view HttpResponse object.

The main site urls.py is referencing 'homepage/', so for anything with that prefix it will be looking at the additional path objects/parameters in your app urls.py. Try:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')),
]
  • Related