2

I am trying to implement SayHello app page. This is my urls.py content

from django.urls import path
from hello.views import myView
urlpatterns = [
   path('admin/', admin.site.urls),
   path('sayHello/',myView),
]

After adding this app to the URL, 'http://127.0.0.1:8000/sayHello/' works fine.

But 'http://127.0.0.1:8000/' reports me the following 404 error page.

Page not found (404)
Request Method:    GET
Request URL:    http://127.0.0.1:8000/
Using the URLconf defined in editdojo_project.urls, Django tried these URL patterns, in this order:

admin/
sayHello/
The empty path 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.

How can I fix this bug?

3 Answers 3

4

That is because you have no routes matching your homepage (which is an empty string in the urls.py file), if you did something like this, for instance, you would see the same HelloWorld in 'http://127.0.0.1:8000/'

from django.urls import path
from hello.views import myView
urlpatterns = [
   path('admin/', admin.site.urls),
   path('',myView),
   path('sayHello/',myView),
]
Sign up to request clarification or add additional context in comments.

Comments

3

bcoz django first finds the corresponding url pattern in urls.py then fires up view from views.py file... path('admin/', admin.site.urls) gets u to http://127.0.0.1:8000/admin and path('sayHello/',myView) takes u to http://127.0.0.1:8000/sayHello but in urls.py u have no url that match up to http://127.0.0.1:8000/ -- that is usally index page or home page,,,, to add index do this -->

urlpatterns = [ 
   path('admin/', admin.site.urls),
   path('sayHello/',myView),
   path('',view),
]

Comments

1

try this

from django.urls import path
from hello.views import myView
urlpatterns = [
   path('admin/', admin.site.urls),
   path('sayHello/',myView),
   path('', sayHello),
]

hope it help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.