How to create a root page in Django

A quick step by step guide on how to create a root page in your new Django app.

Create a file at the root of the app (not the project):

Import the HttpResponse module from django:

from django.http import HttpResponse

Define the response to a view request, for example a welcome page:

def welcome(request):
  return HttpResponse("Hello World")

Open and import the response from the new views file:

from .views import welcome

Add a line to urlpatterns to:

url(r'^$', welcome)

This points the root ‘^$’ to the welcome response we defined in our new script:

Run the server with:

python runserver