Skip to content

6. Add the landing page to the app

Katie House edited this page Sep 15, 2020 · 3 revisions

The file mysite/urls.py determines which view function the HTTP request will map to when the client makes a URL request. For example, in the local django web app, the home page will load with the URL http://localhost:8000/ or a URL path of ''. When this happens, we want to map to the home() function in iris/views.py to render the home page.

To do this, change the mysite/urls.py to the following:

from django.contrib import admin
from django.urls import path
from iris import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
]

Now, we must add the home() function to iris/views.py:

from django.shortcuts import render


def home(request):
    return render(request, 'home.html')

Finally, we need to create a home.html file to render for the landing page. To do this, add the following file iris/templates/home.html. Notice we are creating a new templates/ folder.

In iris/templates/home.html, add this:

<h1>Hello Django World</h1>

Check your new landing page works with:

python manage.py runserver

You should see: