Chapter 6. Deploy Django App

This chapter covers how to deploy your Django app in the production environment. We'll also explain how to manage several software tools and services through the deployment process, such as AWS Lightsail, GitHub, PostgreSQL, Nginx, GCP (Google Cloud Platform), and SendGrid.
What We Cover in This Chapter
The following topics are covered in this chapter:
Overview of Django App Deployment (1)
In this section, we'll discuss the basic concepts of deploying your Django app in the production environment and the importance of making your app accessible to the public.
Overview of Django App Deployment (2)
In this section, we'll dive deeper into the choices involved in the deployment process, such as selecting a hosting service, deciding on the operating system, and choosing the database for production.
Key Steps of Django App Deployment
This part provides an overview of the eight key steps in deploying your Django app from scratch, covering everything from setting up hosting services to configuring production databases and handling email settings.
Hosting Service Initial Settings (1) – AWS Lightsail Setup
Learn how to prepare your AWS Lightsail instance, set up an Ubuntu instance, and attach a static IP address to make your Django app accessible online.
Hosting Service Initial Settings (2) – SSH Remote Connection
This section explains how to establish a secure SSH remote connection between your local machine and the Ubuntu server for remote management of your Django app.
Manage Local Computer and Remote Server Simultaneously
Managing both local development and remote production environments is crucial. We'll cover tips and techniques for handling both simultaneously to avoid errors and ensure smooth workflows.
Tips for Managing Local Development and Remote Production Environment
This section provides important tips for managing differences between local and production environments, focusing on .gitignore
, dependencies, and settings management.
Hosting Service Initial Settings (3) – Clone Project Directory with GitHub
Learn how to push your project code from your local machine to GitHub and then clone it onto your production server to keep both environments synchronized.
Production Database Setup
In this section, we'll walk you through setting up PostgreSQL for production and configuring the database settings for your Django app.
Django App Production Configuration (1) – Edit settings.py
Learn how to adjust your settings.py file to configure your app for both development and production environments, including managing environment variables securely using the .env file.
Django App Production Configuration (2) – Production Settings
This section covers the critical production settings that must be configured for optimal security and performance in the production environment.
Django App Production Configuration (3) – django-environ and .env File
Learn how to use the django-environ library to manage environment variables securely, particularly for sensitive information like API keys and passwords.
Static File Settings
Understand how to manage static files for your Django app in the production environment, including the setup of Nginx for static file handling.
Django and Dependency Installation on Production Server
This part explains how to install Django and its dependencies in a virtual environment on your production server to ensure consistency and stability.
Web Server and Application Server in Django
Learn about the key roles of web and application servers in deploying a Django app and how to set them up using Nginx and Gunicorn.
Application Server Setup – Gunicorn
We’ll explain how to configure Gunicorn, an application server, to run your Django app in the background using systemd on your Linux server.
Web Server Setup – Nginx
Set up Nginx as the web server for your Django app, handling static files and forwarding dynamic requests to the Gunicorn application server.
Domain Setup
Learn how to link your web app to a custom domain name, making it more user-friendly and accessible instead of relying on a raw IP address.
SSL Setup – Certbot
This section covers how to use Certbot to obtain and configure a free SSL certificate from Let's Encrypt, enabling secure HTTPS communication for your Django app.
Email Setting – SendGrid
Set up SendGrid to handle email sending in production, including registration, API key creation, and configuring Django settings for email functionality.
Social Login for Production
Learn how to configure social logins for production, including setting up OAuth apps on GitHub and Google, and adjusting the callback URLs for your domain.
Manage Local Development and Remote Production Environment
In this final section, we summarize how to effectively manage both the local development environment and the remote production environment, covering the use of different requirements files, settings configurations, and common commands for each environment.
Learn offline for better focus!
A book for this course is available on Amazon.
Django Visual Guide
Step-By-Step Manual for Complete Beginners to Mastering Django, Python, and Web Development.
Get the Book Now