Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python page not found 404 django

shivajikobardan

Legendary Coder
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.
View attachment 315342

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?
 
I know nothing about Django, but I find its error page quite clear and concise. It says it is using the configuration file taskmate.urls which has the URLs admin/, task/ and todolist/, but not about and contact.
So isn't this just a matter of updating that file ?
 
What exactly did you try and how exactly did you fail ? Details matter !
Does that file exist at all ? Or can't you locate it ?
What usually helps me in cases like this is to run Process Monitor on the webserver process (IIS? Tomcat ?) and see what files it opens (or tries to open).
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom