Python Page not found 404 django-python

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
AI Thread Summary
The discussion centers on resolving a 404 error when accessing the "about" and "contact" pages in a Django application. The user aims to achieve specific outputs for the URLs 127.0.0.1:8000/about and 127.0.0.1:8000/contact, but both return a "page not found" error. The current URL configuration in the main project’s urls.py file does not include paths for these pages, leading to the issue. The user suspects that the problem lies in the main urls.py file, which currently includes paths for 'task/' and 'todolist/', but lacks specific entries for 'about/' and 'contact/'. Suggestions emphasize the need to add a path for 'contact/' similar to the one for 'about/'. The discussion also highlights the importance of understanding Django's nested path routing to properly configure the URLs and achieve the desired functionality.
shivajikobardan
Messages
637
Reaction score
54
TL;DR Summary
page not found in django, how do I fix this issue?
Goal:

127.0.0.1:8000/about
Should give:
welcome to to about us page

127.0.0.1:8000/contact
Should give:
welcome to contact page

Problem:
Both are giving "page not found at /"
Code:
Page not found (404)

Request Method:    GET

Request URL:    http://127.0.0.1:8000/contact/
Using the URLconf defined in taskmate.urls, Django tried these URL patterns, in this order:
1) admin/

2) task/

3) todolist/

The current path, contact/, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

This is my folder structure.
1665382902057.png


Currently, my urls.py of taskmate is:

Python:
from django.contrib import admin

from django.urls import path, include
urlpatterns = [

    path('admin/', admin.site.urls),

    path('task/',include('todolist_app.urls')),

    path('todolist/',include('todolist_app.urls')),

]

And for todolist_app, these are my details:

Urls.py:

Python:
from django.urls import path

from todolist_app import views

#from . import views

urlpatterns = [

    path('', views.todolist),

    path('contact', views.contact,name='contact'),

    path('about', views.about, name="about"), #the path can be anything.

]

Views.py:

Python:
from django.shortcuts import render

from django.http import HttpResponse
# Create your views here.

def todolist(request):

    context={'welcome_text':"welcome to todo list app"}

    return render(request, 'html/todolist.html',context)
def contact(request):

    context={'welcome_text':"welcome to contact page"}

    return render(request, 'html/contact.html',context)
def about(request):

    context={'welcome_text':"welcome to to about us page"}

    return render(request, 'html/about.html',context)
I'm suspecting that the problem is in my main project urls.py as I've not included any details about contact and about URLs there. So, I did this there.

Python:
from django.contrib import admin

from django.urls import path, include
urlpatterns = [
    path('admin/', admin.site.urls),

    path('task/',include('todolist_app.urls')),

    path('todolist/',include('todolist_app.urls')),

    path('about/',include('todolist_app.urls')),

]

The website runs but the goal isn't achieved.
It shows what the URLs
http://127.0.0.1:8000/task/
And
http://127.0.0.1:8000/todolist/
Show.
How do I fix this issue?
 
Last edited:
Technology news on Phys.org
shivajikobardan said:
I'm suspecting that the problem is in my main project urls.py as I've not included any details about contact and about URLs there.
You don't need to suspect, you just need to read the error message which tells you that.

shivajikobardan said:
So, I did this there.
[CODE lang=Python title=taskmate/urls.py]from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('task/',include('todolist_app.urls')),
path('todolist/',include('todolist_app.urls')),
path('about/',include('todolist_app.urls')),
][/CODE]
[See how I tidied that up to remove additional whitespace and added a title to make it clear what file it was? You should do this when posting.]

But that still doesn't have an entry for path('contact/', ...)!

Learn about how nested path routing works here: https://docs.djangoproject.com/en/4.0/topics/http/urls/#url-namespaces
 
It's not working to achieve the goal i posted in question even after adding stuffs in taskmate/urls.py. As I said above.
 
shivajikobardan said:
It's not working to achieve the goal i posted in question even after adding stuffs in taskmate/urls.py. As I said above.
But you did not add the right stuffs in taskmate/urls.py. As I said above.
pbuk said:
But that still doesn't have an entry for path('contact/', ...)!
 
as i said adding entry like i added for "about" there will lead to same page that i get when i hit 127.0.0.1/task and 127.0.0.1/todolist
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top