Page not found 404 django-python

  • Context: Python 
  • Thread starter Thread starter shivajikobardan
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around a Django web application issue where specific URLs for "about" and "contact" pages are returning a 404 error. Participants are examining the URL configuration in the Django project and the associated views to resolve the problem.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes the expected behavior of the URLs for "about" and "contact" pages and notes that both are returning a 404 error.
  • Another participant suggests that the issue lies in the main project's urls.py file, indicating that the necessary URL patterns for "contact" and "about" are not included.
  • A participant points out that the error message indicates the missing URL patterns and emphasizes the need for proper routing.
  • There is a reiteration that the participant did not add the correct entry for the "contact" path in the urls.py file.
  • One participant expresses frustration that even after modifications, the goal of accessing the desired pages is not achieved.
  • Another participant argues that simply adding an entry for "about" will not resolve the issue, as the routing for "contact" is still missing.

Areas of Agreement / Disagreement

Participants generally agree that the URL configuration is incomplete, particularly regarding the "contact" path. However, there is disagreement on the effectiveness of the changes made and whether they adequately address the problem.

Contextual Notes

There are unresolved issues regarding the proper configuration of URL patterns in Django, particularly concerning nested routing and how to correctly include paths for different views.

shivajikobardan
Messages
637
Reaction score
54
TL;DR
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
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
Replies
3
Views
3K
Replies
9
Views
14K
  • · Replies 3 ·
Replies
3
Views
5K
  • Sticky
  • · Replies 2 ·
Replies
2
Views
504K