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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top