How to deploy django to production using DigitalOcean (Part-1)

In the part 1 of this tutorial, we will be looking at how to set up a digitalocean project and run Django web app on it

Introduction

Hello everyone. In one of our earlier articles, we learned how we can deploy keras models to production using flask. While Django and flask each have their own specialties, one of the major advantages of Django over flask is that Django is a full-stack python web framework. The batteries included in Django makes it easier for Django developers to accomplish common web development tasks like user authentication, URL routing, database schema migration, and functional admin interface. You can follow the article, Flask vs Django to learn in detail the differences between these two frameworks.

Now, if you’ve tried web development using Django before you know that it includes a simplified development server for testing your code locally. But for anything production related, a more secure and powerful web server is required. We will be using the following environment and apps to deploy Django to production in our DigitalOcean droplet.

  • Ubuntu 18.04 x64  as the Operating System
  • PostgreSQL as Database
  • Nginx as the web server
  • Gunicorn application server to interface with our applications

Setting up DigitalOcean account

If you already have a DigitalOcean account, you are free to skip this step. But if you don’t, you can sign up for it by clicking this link and you’ll get $50 in credit over 30 days. Once you have completed the signup process, you will need to create a new project. To create a new project, click on the New Project on the top left of the screen or click on this link. You will see a page that looks like the one below:

DigitalOcean new project

Fill in the Name and description of your project and select it’s intended use from the dropdown and click on Create Project.

On the next screen, you will see Move resources into [your project name]. Click on Skip for now.

Now, you will need to create a droplet. To create a new droplet, navigate to Create > Droplets from the top right of the screen or by following this link. You will see a page that looks like the one below:

DigitalOcean new droplet

Select your desired configuration for the droplet and click on Create Droplet. Be sure to select Ubuntu 18.04 x64 in the Distributions section (Default at the time of publishing this article). For me, the configuration is:

  • Distribution: Ubuntu 18.04 x64
  • Choose a plan: Standard, $5/mo
  • Enable Backups: Unchecked
  • Datacenter Region: San Francisco
  • Select Additional Options: Everything unchecked
  • Authentication: One-time password
  • How many Droplets?: 1
  • Choose a hostname: ubuntu-s-4vcpu-8gb-sfo2-01 (Default)
  • Add tags: Leave blank
  • Select Project: [Select the project name you used on create project window]



1 Trackbacks & Pingbacks

  1. How to deploy django to production (Part-2) | pytorials.com

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.