Setting up the home page template

Let's now create a web page that loads when the / route is accessed. Remember the api app that we created in the project? Let's make the index page a part of this app for the sake of simplicity. While it is possible to create this route in the urls.py file of the mysite app, we will provide the api app with its own route handling file.

Let's begin with the steps for setting up the home page template:

  1. Create a file, urls.py, inside the api folder. The complete path of this file relative to the project directory would be mysite/api/urls.py. Inside this file, let's add the / route, using the following code:
from django.urls import pathfrom . import viewsurlpatterns = [ path('', views.indexView), # This line ...

Get Hands-On Python Deep Learning for the Web now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.