Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Django IntroductionChapter 6. Deploy Django App

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Cloning Code to Webserver with GitHub

Summary of the initial settings

We split this step into three sections. This lesson covers the last section.

  1. AWS Lightsail setup
    • Prepare AWS Lightsail and create an Ubuntu (20.04 LTS) instance
    • Obtain a static IP address and attach it to the instance
  2. SSH remote connection between the local computer and the Ubuntu instance
    • Establish an SSH connection between the local computer and the instance
    • Enable the remote access using VS Code
  3. Clone the project directory to the instance using GitHub (this section)
    • Push the project directory from the local computer to the GitHub repository
    • Establish a remote connection between GitHub repository and the Ubuntu instance (register a developer key)
    • Clone the project directory to the Ubuntu instance

Push the project directory from the local computer to the GitHub repository

To transfer your code from the local computer to the server, GitHub (a git repository platform) is often used. If you are not familiar with Git and GitHub, we recommend that you check our 'Git and GitHub Introduction' course.

Git and GitHub Introduction Git and GitHub Introduction

As the process of establishing Git and GitHub requires a lot of explanations. Here, we will mainly cover key points for the Django project code transfer process.

.gitignore

Before you push (send) your project documents to the GitHub repository, you need to create the .gitignore file. There are files or directories you don't want to push to the repository.

You can use gitignore.io to check typical files or directories that should be listed in the .gitignore file for Django apps.

Go to the website, type 'Django', and click the Create button.

gitignore.io

You'll see a list of files or directories like in the example below.

.gitignore file example

Create the .gitignore file directly under the project directory, and copy the list from gitignore.io.

For the virtual environment (venv) directory, add your virtual environment directory name with / at the end. In our case example, add d_env/ to the list.

Push the code to a GitHub repository

After creating a GitHub repository (e.g., project_d ), commit the latest code and push the code to the repository.

Establish a remote connection between the GitHub repository and the Ubuntu instance (register a developer key)

Here are the key steps to register a developer key.

1. Create an ssh key pair from the Ubuntu instance

To generate a key pair, run the command below with your email address.

Command Line - INPUT
ssh-keygen -t ed25519 -C your_email@example.com

You'll be asked to type a passphrase, but you don't need to type it unless you want to increase the security level. If you set a passphrase, you'll need to type it every time you access your GitHub repository later.

Command Line - INTERACTIVE
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

2. Copy the public key

The public key is available under the .ssh directory located under the home directory (i.e., the ubuntu directory). Copy the key and go to the next step.

SSH keys and .ssh directory
.ssh/id_ed25519.pub
ssh-ed25519 xxxxxxxxx your_email@example.com

3. Add the public key to the GitHub repository

Go to your GitHub repository for this project. Under the Settings tab, click on the Deploy keys on the left sidebar. Press the Add deploy key button.

Add the public key in the GitHub repository: Step 1

Add the Title and paste the copied key. Check on Allow write access. This enables you to push the code from the Ubuntu instance to the GitHub repository.

Finally, press the Add key button to complete the process.

Add the public key in the GitHub repository: Step 2

Clone the project code to the Ubuntu instance

Go to the repository and open the <>Code dropdown. Copy a URL for SSH.

GitHub repository URL for SSH

Run the git clone command from the home directory with the copied URL.

Command Line - INPUT
cd
git clone [copied url]

You'll get the project directory in the Ubuntu instance.

Command Line - INPUT
ls
Command Line - RESPONSE
project_d

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Customizing Django Views to Change List Order

Customize Views (1) – Change List Order

Writing Class-Based Views Using Django Generic Views

How To Write Class-Based Views with Generic Views

Performing Database Migrations in Django

Database Migration

Customizing Django Views to Change List Order

Customize Views (1) – Change List Order

Writing Class-Based Views Using Django Generic Views

How To Write Class-Based Views with Generic Views

Performing Database Migrations in Django

Database Migration

Tags:

GitHub

Remote Repository

.gitignore

App Deployment

Developer Key

Django Introduction
Course Content

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment