How to Deploy Django Application

Django comes with a development server that helps run Django projects in localhost. However, to make your web application available worldwide you will need a host machine. Amazon Web Services (AWS) provides EC2 (Elastic Compute Cloud) which is the most popular choice to host Django web applications.

Creating EC2 instance with Ubuntu

Visit AWS Console first and log in. Now follow simple steps to create an EC2 instance with Ubuntu 18.04

Step 1: Select EC2 from AWS Console

EC2 instance

Step 2: Launch a new instance

Launch EC2 instance

Step 3: Select Ubuntu 18.04 server

Select Ubuntu 18

Step 4: Download pem file which will be used as password

Download pem file

Step 5: Wait for initialization to complete

Initialize EC2 instance

Step 6: Setup Security Group to accept HTTP and HTTPS inbound requests

Security GroupsDeploy Django Project on AWS - EC2

Run the series of below commands after logging in to your Ubuntu instance:

sudo apt update & sudo apt upgrade    
sudo apt install python3-pip
python3 -m pip install --upgrade pip
pip install django==3.2                       

To verify run:

python3 --version
pip --version
django-admin --version

Now copy the project from the local machine to the host machine.

scp -i *.pem ubuntu@public_ip:~/
sudo apt install unzip

Run the app and keep running it in the background:

python3 runserver 0:8000

Use Ctrl + a + d to detach the screen

Finally, visit public_ip:8000 in your web browser to access your project.