The home page is the simplest view in the entire project as all it does is display an HTML page. A CBV was used because there is an easy to use generic view with all the functionality required - the
Step 1: Create the Home Page View
Follow the steps below to create the view.
/.../crmeasy/crmapp/marketing/views.pyin your IDE
- Edit it to look like the following
1 2 3 4 5 6 7 8 9
from django.views.generic.base import TemplateView class HomePage(TemplateView): """ Because our needs are so simple, all we have to do is assign one value; template_name. The home.html file will be created in the next lesson. """ template_name = 'marketing/home.html'
Line 1: The first step is to import the TemplateView CBV.
Line 3: The second thing to do is create the HomePage class. This subclasses the TemplateView CBV that was imported in the first step.
Line 7: This last line demonstrates the simplicity of CBVs. The only thing required at this point is to assign a value to
template_name, which has to be a template file (the template will be created in the next lesson).
Step 2: Commit Changes
Execute these commands to commit your changes in Git.
1 2 3 4 5
# add files (venv)$ git add . # commit files (venv)$ git commit -m "created the home page view"