Django Add Main Index Page

Main Index Page

Our project needs a main page.

The main page will be the landing page when someone visits the root folder of the project.

Now, you get an error when visiting the root folder of your project:

Start by creating a template called main.html:

MainGet your own Django Server


{% extends "master.html" %}


{% block title %}

  My Tennis Club

{% endblock %} 

{% block content %}

  <h1>My Tennis Club</h1>




  <p>Check out all our <a href="members/">members</a></p>


{% endblock %}

Create new View

Then create a new view called main, that will deal with incoming requests to root of the project:


from django.http import HttpResponse

from django.template import loader

from .models import Member


def members(request):

  mymembers = Member.objects.all().values()

  template = loader.get_template('all_members.html')

  context = {

    'mymembers': mymembers,


  return HttpResponse(template.render(context, request))


def details(request, id):

  mymember = Member.objects.get(id=id)

  template = loader.get_template('details.html')

  context = {

    'mymember': mymember,


  return HttpResponse(template.render(context, request))


def main( Add Main Index Page