Creating virtual environment for the application

python3 -m venv myapp

image.png

Now let’s create a new project

django-admin startproject myproject

image.png

Creating the application

python3 manage.py startapp myapp

image.png

Configuring Django urls

#urls.py file
from django.urls import path
from myapp import views

urlpatterns = [
    path("",views.index, name="index")
]

image.png

What this code do is that it set the root url “/” and make it call the function named “index” from the views.py file

Now let’s go and make the index function in the views.py

# views.py file
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def index(request):
    return HttpResponse("<h1>Hello Django</h1>")

image.png

The views.py file contain an implementation for index function that will return a response Hello Django when the user visit it.

Now let’s run the application and test it.

python3 manage.py runserver

image.png