Home > Enterprise >  I cant create a page with an empty path in Django
I cant create a page with an empty path in Django

Time:02-20

centralsite/views

def centralsite(request):
    return render(request, 'centralsite/text.html', {})

centralsite/urls

 from django.urls import path
    from . import views

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

urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [path(' ', include('centralsite.urls')),
               path('polls/', include('polls.urls')),
               path('admin/', admin.site.urls),]

error message is: Request Method: GET Request URL: http://localhost:8000/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

^$ polls/ admin/ The empty path didn’t match any of these.

how do i make this empty path work?

CodePudding user response:

Delete whitespace from your path:

urlpatterns = [path(' ', include('centralsite.urls')),    # bad

urlpatterns = [path('', include('centralsite.urls')),     # good

Otherwise, because whitespace is a character, it will look for url with whitespace or .

  • Related