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 views.py 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 urls.py 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 views.py script:

Run the server with:

python manage.py runserver