Listing movies with dummy data
Listing movies involves a series of steps similar to those followed when we implemented the Home and About pages. We will follow the next steps: (i) configuring the movies URL, (ii) defining the views
index
function, and (iii) creating a movies index template.
Configuring the movies URL
In /movies/
, create a new file called urls.py
. This file will contain the path regarding the URLs of the movies app. For now, fill it in with the following:
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='movies.index'), ]
We defined a ''
path, but remember that the project-level URLs file defined a /movies
prefix for this file. So, if a URL matches the /movies
path, it will execute the index
function defined in the views
file. We will implement the index
function next.
Defining the views index function
In /movies/views.py
, add the following in bold:
from...