Page not found 404 django-python

  • Python
  • Thread starter shivajikobardan
  • Start date
In summary, the URL for the goal, "about", doesn't appear to be accessible from the current location.
  • #1
shivajikobardan
674
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
  • #2
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.
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')),
]
[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
 
  • #3
It's not working to achieve the goal i posted in question even after adding stuffs in taskmate/urls.py. As I said above.
 
  • #4
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/', ...)!
 
  • #5
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
 

FAQ: Page not found 404 django-python

What does "Page not found 404" mean?

The "Page not found 404" error is a common error message that appears when a user tries to access a webpage that does not exist on the server. This could be due to a misspelled URL, deleted page, or broken link.

How can I fix a "Page not found 404" error in Django-Python?

To fix a "Page not found 404" error in Django-Python, you can start by checking the URL in your browser to make sure it is correct. If the URL is correct, then you can check your Django project's urls.py file to ensure that the correct URL path is mapped to the correct view. You can also check for any typos or errors in your views.py file.

Can I customize the "Page not found 404" error page in Django-Python?

Yes, you can customize the "Page not found 404" error page in Django-Python. You can create a custom 404.html template and add it to your templates folder. Then, in your project's settings.py file, you can specify the location of this template in the TEMPLATE_DIRS setting.

Why do I keep getting a "Page not found 404" error even though the page exists?

There could be several reasons for continuously getting a "Page not found 404" error even though the page exists. Some possible reasons include incorrect URL mapping in the urls.py file, incorrect file permissions, or a misconfigured web server.

Is a "Page not found 404" error bad for SEO?

A "Page not found 404" error can have a negative impact on SEO if it occurs frequently and for important pages on your website. Search engines may interpret it as a sign of a poorly maintained website. It is essential to fix these errors as quickly as possible to avoid any negative SEO impact.

Back
Top