Home page in Django

Posted under » Django on 13 April 2023

We have learnt how to create an index or home page for the polls app. However, we need a home page for the website itself.

Do do this we have to select one app that we want to make as the home page. Preferably the main app for the website. Let's call it the display app.

First, we change the main urls.py file at www/briles/briles/urls.py

urlpatterns = [
    path('', include('display.urls')),

What this line do is to call urls.py from the display app to route traffic. So we now go to the urls.py at the display app (www/briles/display/urls.py ). The top imports remains the same

from django.urls import path
 from . import views

urlpatterns = [
    path('', views.index, name='index'),

So if nothing is specified then the index function (def index) will be called from the display > views.py. If something is specified on the url, then it will look for the function at the display app.

We will do the home page using a template like the home page for the polls app. Edit the views.py

from django.shortcuts import render

def index(request):
    return render(request,'display/index.html')

So we create the home page html of your choice at the www/briles/display/templates/display/index.html.

Next we create the user login page.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data