Fixing the Index Page#

If you carefully followed the Django instructions you pobably noticed that going to the index page of your web application takes you to a 404 error page. That’s because you removed the default route that matches URLs that aren’t polls/ or admin/. Here’s how to fix that.

Update your mysite/urls.py to have a redirect when you go to the default URL:

from django.contrib import admin
from django.urls import include, path
from django.views.generic.base import RedirectView

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