Author avatar

Kimaru Thagana

Introduction to Web Development in Python and Django

Kimaru Thagana

  • Oct 2, 2020
  • 7 Min read
  • Oct 2, 2020
  • 7 Min read
Web Development
Back End Web Development
Server-side Frameworks


Web development became popular due to the widespread accessibility of the web, especially for commerce. Once businesses quickly realized they could offer their products and services on the web, this created a demand for web development that has never slowed down.

Web development can be divided into three major parts:

  1. Backend development: This is concerned with business logic, data storage, and processing.
  1. Frontend development: This is concerned with how the user interacts with the system and mainly includes user experience (UX) and user interface (UI) design.
  1. API/middleware development: This is concerned with how the backend and frontend apps communicate.

This guide will explore developing web apps using the Python framework Django. This framework mainly addresses backend and API/middleware development. It is therefore assumed that you have at least intermediate level knowledge in Python.

Python Web Development

Web development in Python picked up to bring the data wrangling and processing power of Python to the web. Some popular sites built on Python/Django include Disqus, Instagram, and Mozilla, among others. More information can be found here.

Hello World in Django

To get started with Django, install it using this command on your terminal.

1pip install django

To start a new Django project, run the starter command, which creates a boilerplate project.

1django-admin startproject hello_world

You now have a Django project with basic boilerplate code. Within a Django project, there can exist several apps.

An app can be described as a library of code representing a discrete part of a larger project. A Django app requires at least one app to run. To create an app, use the script and pass the startapp command, as demonstrated below.

1python startapp myapp

At this point, you have a Django project called hello_world and, within it, an app called myapp.

App Boilerplate

The app folder comes with starter files that are critical for any Django app. These are:

  1. Where app configurations are defined
  1. Where model configurations are defined in relation to the project admin page
  1. Where database tables are defined as Models
  1. Where Django views are defined. These are objects that define how content is displayed on a web page.

For this project, you will add a new file and name it Copy the code below into the file under the myapp/ folder.

1from django.urls import path
2from .views import home
3urlpatterns = [
4    path('', home,name='home'),

The function of this file is to define which view will be accessed by a user if they access a certain URL. In this case, when they access the root URL, they will be directed to the home view.

The next step is to develop the home view. Open and copy the code block below.

1from django.shortcuts import HttpResponse
3# Create your views here.
4def home(request):
5    return HttpResponse("Hello world from Django")

The above creates a view called home, which returns an HTTPResponse. This means it will be just plain text. In Django, there are class-based and function-based views. Read more about them here.

The app is now complete but needs to be connected to the main project since at runtime, the user accesses the project at root level and then through URL resolving and is directed to the appropriate app. To connect the app to the main project, add it to the INSTALLED_APPS list in the file in the hello_world/ project folder; also, link it in the main file in the project.

To add to the INSTALLED_APPS list, navigate to the file and replace the current list with the list below.

2    'django.contrib.admin',
3    'django.contrib.auth',
4    'django.contrib.contenttypes',
5    'django.contrib.sessions',
6    'django.contrib.messages',
7    'django.contrib.staticfiles',
8    # local app
9    'myapp',

To link the project URL to the app URL, navigate to the hello_world/ file and copy the following code block.

1from django.contrib import admin
2from django.urls import path, include
4urlpatterns = [
5    path('admin/',,
6    path('', include('myapp.urls'))

With the second item in the list, you are directing that if there is no parameter from the root URL (path empty), traffic should be directed to the URL's file in the myapp app. Within the myapp URL's file, the root URL is resolved to display the home view. This is how you will display the Hello world from Django message.

Running the Project

To run the project, run the command:

1python runserver

This will execute the project using a Web Server Gateway Interface (WSGI) that is inbuilt and necessary to run Python projects on the web. The site is accessible by default on

Sample Screen

After running the runserver command, upon accessing the default Django URL, you should see a hello world page similar to the one below.

Landing screen


Web development in Django is quite a wide field. The skills learned in this guide offer an introduction to what is required for positions such as a backend or full-stack Python/Django web developer. To further build on this guide, research the following aspects of web development using Django:

  1. Django Forms: Learn how to collect data from users and pass to Django views and forms for further processing. Get started here
  1. Handling static files and upload data: Learn how to handle uploading of files and media. Get started with the official docs
  1. Using Django APIs with the Django Rest Framework (DRF): Developing a Django app with API capabilities. Starter tutorial can be found here.
  1. Django Databases: Performing database operations and migrating models (Tables). Quickstart guide.
  1. Jinja templating engine: Learn how to use Jinja to manipulate HTML code blocks programmatically. Quickstart guide.
  1. Deploying a Django app to a live server: Learn how to share your Django app on the cloud. Get started with Django on Digital ocean here.