Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The empty path didn't match any of these:

i am using python 3.8 and getting error when i launch server:

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

polls/
admin/
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.

my polls/urls.py:

   from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

my djangoProject/urls.py:

  from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url("polls/", include('polls.urls')),
    url("admin/", admin.site.urls),
]
like image 260
zeerker0 Avatar asked Sep 14 '25 13:09

zeerker0


1 Answers

The root urls contains two items: polls/ and admin/. This thus means that if you visit the root URL (127.0.0.1:8000/), it will not trigger any view, since no view has been "attached" to that URL pattern. You thus will have visit a page to trigger the view, or change the URL patterns to enable visiting the index view if you visit the root URL.

Option 1: visit /polls/

You can visit the page by visiting:

127.0.0.1:8000/polls/

Option 2: link index to the root URL

You can change the URL patterns to trigger index when visiting the root URL with:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    #   ↓↓ empty string
    url('', include('polls.urls')),
    url('admin/', admin.site.urls),
]
like image 188
Willem Van Onsem Avatar answered Sep 16 '25 03:09

Willem Van Onsem