Starting Django


Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Why Django?

1. Ridiculously fast.

2. Reassuringly secure.

3. Exceedingly scalable.

Getting started with Django

Before starting Django you need to install django and python to your computer.

step 1 .install python from
step 2. install pip using python apt install python3-pip
step3. install Django

  pip install django 

Creating your very first Django project

django-admin startproject my_firts_proj

after starting the project you can see several pre installed python files in your project section, further diving to the project folder you will find files like,,, and at last, you will find the file

├── my_first_proj
│   ├──
|   ├──
│   ├──
│   ├──
│   └──

understanding python files

  • indicates that the files in the folder are part of a Python package. Without this file, we cannot import files from another directory which we will be doing a lot of in Django!
  • allows for an optional Asynchronous Server Gateway Interface to be run
  • controls our Django project’s overall settings
  • tells Django which pages to build in response to a browser or URL request
  • stands for Web Server Gateway Interface which helps Django serve our eventual web pages.

The file is not part of django_project but is used to execute various Django commands such as running the local web server or creating a new app.

Running Django application

python runserver

after running the Django application you will find the development server in your terminal as
copy the link and paste it into your browser

Django welcome page


Starting your first django application
you can start your django application using

python startapp myapp

after starting your application you have to register your application to your django project

to register your app you have to add your app in installed applications you can find installed application on file located at your project folder

    # my apps 

Saying Hello world

In Django, four separate files aligning with this MVT pattern are required to power one single dynamic (aka linked to a database) webpage:

  • template.html (any HTML file will do)

However, to create a static webpage (not linked to a database) we can hardcode the data into a view so the model is not needed. That’s what we’ll do here to keep things simple.

The next step is therefore to create our first view. Start by updating the file in our myapp app to look as follows:

# myapp/
from django.http import HttpResponse
def homePageView(request):
    return HttpResponse("Hello, World!")

Moving along we need to configure our URLs. In your text editor, create a new file called within the myapp app . Then update it with the following code:

# myapp/
from django.urls import path
from .views import homePageView
urlpatterns = [
    path("", homePageView, name="home"),

On the top line we import path from Django to power our URL pattern and on the next line we import our views. By referring to the file as .views we are telling Django to look within the current directory for a file and import the view homePageView from there.

Our URL pattern has three parts:

  • a Python regular expression for the empty string ""
  • a reference to the view called homePageView
  • an optional named URL pattern called "home"

The last step is to update our my_first_projs/ file. It’s common to have multiple apps within a single Django project, like myapps here, and they each need their own dedicated URL path.

# django_project/
from django.contrib import admin
from django.urls import path, include  # new
urlpatterns = [
    path("", include("myapp.urls")),  # new

We’ve imported include on the second line next to path and then created a new URL pattern for our pages app. Now whenever a user visits the homepage, they will first be routed to the pages app and then to the homePageView view set in the myapp/ file.

This need for two separate files is often confusing to beginners. Think of the top-level my_first_proj/ as the gateway to various url patterns distinct to each app.

We have all the code we need now. To confirm everything works as expected, restart our Django server:

# Windows

 python runserver

# macOS /linux 
 python3 runserver

If you refresh the browser for it now displays the text “Hello, World!”

Hello World homepage


4 thoughts on “Starting Django”

Leave a Comment