[Django]-How to solve "Page not found (404)" error in Django?

27πŸ‘

βœ…

You are getting the 404 because you haven’t defined a url pattern for http://127.0.0.1:8000/ yet.

You should be able to view the admin site at http://127.0.0.1:8000/admin/ and your food posts at http://127.0.0.1:8000/foodPosts/.

To add a url pattern for the homepage, uncomment the following entry in your urls.py, and replace homefood.views.home with the path to the view you want to use.

url(r'^$', 'homefood.views.home', name='home'),
πŸ‘€Alasdair

3πŸ‘

Basically the answer to this to add a entry in the project urls.py file as blank example:

path('', include('MYAPP.urls')),

and in the app urls.py you add this

url('MYAPP', views.index),

make sure in the settings.py you include your app also make sure in the app urls.py you import your views

2πŸ‘

I had this error too and the solution was to change double quotes to single quotes for the name= parameter in the urls.py file of the concerned app!

path('register', views.register, name='register')
πŸ‘€cheznead

1πŸ‘

Not directly relevant to the OP, but maybe useful for others:

My admin pages all went 404 after I accidentally removed the trailing slash from the path() route (django 3.2):

urlpatterns = [
    path('admin', admin.site.urls),  # trailing slash missing...
    path('', include('myapp.urls'))
]

This was easily fixed by restoring to 'admin/'.

πŸ‘€djvg

0πŸ‘

It’s work for me by just added / in the end of β€˜users’
in urls.py app file
look like this

path('users/', get_users, name='users')
πŸ‘€AMMAR YASIR

0πŸ‘

I got the same error below:

Page not found (404)

Because I didn’t put / after test/<int:id> as shown below:

urlpatterns = [     # ↓ Here
    path('test/<int:id>', views.test, name="test")
]

So, I put / after test/<int:id> as shown below, then the error was solved:

urlpatterns = [      # ↓ Here
    path('test/<int:id>/', views.test, name="test")
]

0πŸ‘

You only see the landing page when there are NO URLS defined:

enter image description here

As soon as you configure a URL (e.g foodPosts/) , the / route will NOT show the landing page unless you explicitly define a / route in urls.py

Hence you don’t see that rocket with this link : http://127.0.0.1:8000/

πŸ‘€dgor

Leave a comment