In this tutorial, we will create a basic Python Django Helloworld application, this will help you get started with Python Django Framework from the basics.

1. Technologies:

  • Python 3.7, 3.8
  • Django framework 3.1

2. Python Django Helloworld Application

Step by step basic Django application development, let’s start from setting the virtual environment.

2.1. Create Virtual Environment

Using the following commands (inside terminal or command prompt) create a folder ‘Django-HelloWorld’ and within it create a virtualenv ‘env’. You can choose any name for the virtualenv (or venv).

For Linux users:

mkdir Django-HelloWorld
cd Django-HelloWorld/
python3 -m venv env
source ./env/bin/activate

For Windows users, to create and start a virtual env:

virtualenv env

The virtual environment is now created and activated. You should see a (env) at the beginning of the command line, indicating ‘env’ virtual environment is activated. It can be deactivated anytime using the command ‘deactivate’.

2.2. Install Django

Install Django-framework within the virtualenv using the following command:

python -m pip install Django

Confirm installation using:

python -m django --version

You should get the version number ‘3.1.3’ or something similar.

2.3. Creating a Project

We start by creating a Django project. This will auto-generate some code needed to run the application. This includes settings for running the application, database configuration, URLs patterns, debugging logs, etc.

Run the following command :

django-admin startproject helloDjango

Here, ‘helloDjango’ is the name of the project and you can name it as you want.

Running this command generates the following files:

Project Structure
|-- helloDjango
|   |--
|   |--
|   |--
|   |--
|   `--
  • helloDjango/: root project directory
  • A command-line utility that allows you to interact with the Django project in multiple ways. Also, do not edit any content of this file.
  • helloDjango/ an empty to mark the directory as a python package.
  • helloDjango/ Contains the settings for the Django Project
  • helloDjango/ Contains the URL paths for the Django project
  • helloDjango/ An entry-point for ASGI-compatible web servers to serve your project.
  • helloDjango/ An entry-point for WSGI-compatible web servers to serve your project. and files are not required for development purposes and should be left untouched.

2.4. Running Django Application

Now it is time to run the application. Ensure you are in the root directory (where is located) and use the command:

python runserver

There will be some migration errors, we don’t have to worry about them now in this simple application.

In a browser, open the URL localhost:8000, and you should see a welcome screen with the message “The install worked successfully! Congratulations!“.

Next, we actually start writing some code.

2.5. Python Django Helloworld Example

A Django application consists of multiple apps. These are like the sub-units or submodules of a bigger project, with each app taking care of one functionality or a feature of the entire application.

Terminate the running server using Ctrl+C.

Run this command from the root directory to create an app named ‘hello’.

python startapp hello

This will create a directory ‘hello’ with the following file structure:

App Directory
|-- migrations
|   `--
  • Contains the database layout with some additional metadata
  • Here we can register the models with django-admin
  • Configuration file for the app
  • Used for writing tests. Django uses its own testing framework
  • Contains the main logic for the app.
  • migrations/: This directory contains the changes that are made to create the current database schema.

Next, add our functionality for the app in the file hello/

from django.http import HttpResponse
def helloWorld(request):
    return HttpResponse("Hello World")

We create the helloWorld() method, that returns an HttpResponse “Hello World”, upon receiving a request.

Now, we need to specify an URL, where we want to see our output.

For this create a file inside the app directory hello/ with the following content.

from django.urls import path
from . import views
urlpatterns = [
    path('', views.helloWorld),

Next, create a URL pattern for this app in the URL patterns for our project, ie. in the file helloDjango/

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
    path('hello/', include('hello.urls')),

Thus, whenever we go to the URL localhost:8000/hello/, the helloWorld() view (or function) in the file hello/ will be called.

We need to list our app in the INSTALLED_APPS list of our project.

Go to helloDjango/ and add our newly created app’s name to the INSTALLED_APPS list, which should now look like this:


Run your application using

python runserver

Now, navigate to http://localhost:8000/hello/ and you should see the “Hello World” text on the screen.

With this basic application, you can understand how to link the views and the URLs.

3. References:

Download Source from GIT:

Happy Learning 🙂