Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Page not found at /about/. The current path, about/, did not match any of these. Why can't django follow my URL path?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')),
]

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading