This article will cover how to deploy your Django app to an Ubuntu Droplet from Digital Ocean

Luckily you don't have to learn web server configuration or even SSH into the droplet.

Let's start, it will take us less than 15 minutes to get your app running

If you are looking for tutorial for another cloud provider checkout out one of these:

Table of contents

Requirements

  1. An application in Git repository
  2. Digital Ocean account
  3. Appliku account

Django Application

The application used for this tutorial can be found here: https://github.com/appliku/djangotutorial

Your app should be pushed into a git repository. You can use GitHub, GitLab.

For ease of deployment we have the following recommendations:

  • have the requirements.txt file in the root of your git repository. Don't forget to add gunicorn(or alternative) and psycopg2-binary==2.9.5 for Postgres support (or psycopg[binary])
  • Your app needs to respect environment variables like DATABASE_URL for the database credentials, ALLOWED_HOSTS for the list of allowed domains, SECRET_KEY and REDIS_URL if applicable.
  • Please, don't forget to have DEBUG turned off when you deploy to a publicly accessible environment.

We have a full How to Start and Deploy a Django Project if you want to learn more

Also: check our SpeedPy.com SaaS boilerplate

Digital Ocean Account

If you don't already have a Digital Ocean account, Sign up now

Go here to create a new Digital Ocean API Token Create a digital ocean API token

After creating token, save it to a safe place, you will need it in a few moments.

Appliku Account

If you don't already have an Appliku Account create it by going here: Appliku Sign Up

Click on "Add a server" Appliku dashboard: Click on "Add a server"

Click on "Setup Credentials" for Digital Ocean

Appliku dashboard: Click on "Setup Credentials" for Digital Ocean

Paste your token that you created earlier in Digital Ocean dashboard and click "Test & Save Credentials" Appliku dashboard: Paste your token that you created earlier in Digital Ocean dashboard

Status should say "Active" if the key was correct

Appliku dashboard: DigitalOcean credentials status showing Active

Go to "Servers" Appliku dashboard: Go to "Servers"

Then "Add Server" Appliku dashboard: Then "Add Server"

You can now select the "Digital Ocean" provider Appliku dashboard: You can now select the "Digital Ocean" provider

Select a region, droplet type and droplet size and click "Create Droplet" Appliku dashboard: Select a region, droplet type and droplet size

You will be taken to the list of servers and you can see your new server there. Click on its name.

Appliku dashboard: You will be taken to the list of servers and you can see your new server there

You can see that Appliku is waiting for droplet being fully booted to start the setup process Appliku dashboard: You can see that Appliku is waiting for droplet being fully booted to start th...

You can click on "Setup Logs" tab to see the logs of setup process

Appliku dashboard: You can click on "Setup Logs" tab to see the logs of setup process

When server setup is finished you will see stats and "Setup Status" on the left will say "Finished".

Appliku dashboard: When server setup is finished you will see stats and "Setup Status" on the lef...

Adding an application

Click on the "Applications" menu link Appliku dashboard: Click on the "Applications" menu link

You will get to the Git Provider selection. Appliku dashboard: git provider selection screen

Creating application from GitHub

Select the "Setup Credentials" for GitHub. Appliku dashboard: Select the "Setup Credentials" for GitHub

You need to get a personal token from GitHub.

Go to this link to create a token: https://github.com/settings/tokens

GitHub: Go to this link to create a token

Click on Generate new token -> Generate new token(Classic) Fill in the note, select expiration date, check the "repo" checkbox and "user:email"

GitHub: Fill in the note, select expiration date, check the "repo" checkbox and "user:email"

GitHub: Fill in the note, select expiration date, check the "repo" checkbox and "user:email" (2)

And click "Generate token".

Copy the token from the next page.

GitHub: Copy the token from the next page

Go back to Appliku dashboard and paste the GitHub Token, and click Test Credentials and Save

Appliku dashboard: Go back to Appliku dashboard and paste the GitHub Token

Status must change to "Active".

Click on the logo in top left corner to get back to your team and go to Applications again and create an app, select GitHub.

Appliku dashboard: Click on the logo in top left corner to get back to your team and go to Applic...

Fill the form with the app name, select the repository with your application, branch and select the server, click on "Create Application". Appliku dashboard: Fill the form with the app name, select the repository with your application...

You will see your app has been created, but not yet deployed. Appliku dashboard: You will see your app has been created, but not yet deployed

Creating application from GitLab

Alternatively if you use GitLab you should add credentials for GitLab and create an app from GitLab.

Go to Applications menu link, Click "Add Application" and Setup credentials for GitLab.

Appliku dashboard: Go to Applications menu link, Click "Add Application" and Setup credentials fo...

You need to create a Personal Access Token here: https://gitlab.com/-/profile/personal_access_tokens

Give the key a name, set or clear expiration date, select "api" checkbox and click "Create Personal Access token"

GitLab: Give the key a name, set or clear expiration date, select "api" checkbox

Copy the token and paste it in Appliku dashboard.

Appliku dashboard: Copy the token and paste it in Appliku dashboard

After you click "Test Credentials and Save" the Status should turn green and say "Active".

Appliku dashboard: After you click "Test Credentials and Save" the Status should turn green and s...

Click on the logo to go back to your team, go to Applications, Add Application and select GitLab

Appliku dashboard: Click on the logo to go back to your team, go to Applications, Add Application...

Give your application a name, pick repository and the branch, select the server and click "Create Application"

Appliku dashboard: Give your application a name, pick repository and the branch, select the server

Setup the app

Databases

First, create a Postgres Database. Click on Add Database on the right

Appliku dashboard: First, create a Postgres Database

Select the Postgres 16 option and click "Create database" Appliku dashboard: Select the Postgres 16 option

Your database will start deploying, wait for the deployment status to become "deployed". Appliku dashboard: Your database will start deploying, wait for the deployment status to become "...

Define processes

Let's tell Appliku how to run your app

On the Application Overview page you will see a red triangle saying "No processes found". Click on the "Add Processes" button. Appliku dashboard: Click on the "Add Processes" button

Add two processes:

  • one MUST be called web to answer to HTTP requests and command should be gunicorn project.wsgi --log-file -(pay attention to the last dash). It can be slightly different for your project
  • second one MUST be called release and this is the command that will be executed after each successful deployment. If not specified it will default to python manage.py migrate. I recommend to create a bash script if your app needs to run several commands executed on each release. In our example, the command is bash release.sh Appliku dashboard: second one MUST be called release and this is the command that will be execute...

Click save and deploy button, a deployment will start.

Environment variables

Go to the "Environment Variables" tab and add env vars needed for your project.

At least specify the SECRET_KEY and ALLOWED_HOSTS. These variables should be used by your app you can check here how to do that: https://github.com/appliku/djangotutorial/blob/master/project/settings.py

The SECRET_KEY variable value should be some long hard to guess string. Appliku dashboard: The SECRET_KEY variable value should be some long hard to guess string

The ALLOWED_HOSTS variable should be a list of domains on which your app is accessible. As I already mentioned above, don't hardcode this, but make your app respect this environment variable.

By default, each app in Appliku receives a subdomain APPNAME.applikuapp.com, so in our example it should be mydjangoapp.applikuapp.com. If you add custom domains, make a comma-separated list like this mydjangoapp.applikuapp.com,example.com,www.example.com. You can disable the default subdomain in build settings.

When you are finished with environment variables click the "Save and deploy" button and deployment will start.

Reviewing application logs

From the Application Overview page you can go to App Logs to check if there are any errors.

Appliku dashboard: From the Application Overview page you can go to App Logs to check if there ar...

Appliku dashboard: From the Application Overview page you can go to App Logs to check if there ar... (2)

Open your application

Appliku dashboard: Open your application

To access your app click on "Open App" and click on the domain name. It will open your app in a new window.

For a complete Django deployment reference, see the Deploy Django guide in our documentation.

Weighing a Droplet you own against DigitalOcean's App Platform? See how deploying to a server you control compares in Appliku vs DigitalOcean App Platform, or browse every option in our platform comparison.