Python - How to Set Up a Simple HelloWorld Django App

Published on Nov. 26, 2017, 6:14 a.m.

The purpose of this post is to provide a set of instructions to create a simple helloworld app in Django. This app can then be used for testing purposes in other posts I've written.

Set up virtual environment:

# pyenv global 3.6.4
# pyenv virtualenv deploy_django
# pyenv local deploy_django

Set up Django helloworld project:

# pip install django
# startproject helloworld
# cd helloworld
# ./ startapp web
# ./ runserver

Check to make sure you can access it at http://localhost:8000/. You should see the familiar Django welcome page. Now go ahead and close the Django dev server (on Linux a control-C should work).

Open helloworld/ and add the 'web' app:



Open helloworld/ and change the urls:

from django.conf.urls import url
from django.contrib import admin
from web.views import index

urlpatterns = [

Save Open web/ and add:

from django.shortcuts import render

def index(request):
    return render(
            'message': 'Hello World!',

Save Create a new directory called web/templates.

# mkdir web/templates

Add a file in web/templates called index.html and add the following:

<!DOCTYPE html>
    <title>{{ message }}</title>
    <p>{{ message }}</p>

Let's start the Django dev server and navigate to http://localhost:8000/. You should see "Hello World!". At this point, we have a working Django helloworld project.

If this blog is helpful, please consider helping me pay it backward with a coffee.

Buy Me a Coffee at