Django One-Click Application

Django is a high-level Python framework for developing web applications rapidly. DigitalOcean’s Django One-Click Application quickly deploys a preconfigured development environment to a Droplet with Django, Nginx, Gunicorn, and Postgres.


Droplets created using this One-Click have the following software components:

Component Version
Linux Ubuntu 18.04.1
Django Latest from APT
Nginx Latest from APT
Gunicorn Latest from APT
Postgres Latest from APT
Postfix Latest from APT
Certbot Latest from APT

In addition to the package installation, the One-Click also:

  • Enables the UFW firewall to allow only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) access.

  • Creates the django system user.

  • Configures Nginx for Django.

  • Sets up the Postgres user and database, and syncs the database with Django.

  • Creates the Gunicorn Systemd service file and starts Gunicorn.


After you create a Django One-Click Droplet:

  • The Django user password, Postgres password and secret keys are in /root/.digitalocean_passwords.

  • The Django project is served by Gunicorn, which listens on /home/django/gunicorn.socket.

  • Gunicorn is proxied by Nginx, which listens on port 80. The Nginx configuration file is located at /etc/nginx/sites-enabled/django.

  • Gunicorn is started on boot by a Systemd file at /etc/systemd/system/gunicorn.service.

    This Systemd script also sources a configuration file located at /etc/gunicorn.d/ that sets the number of worker processes. You can find more information on configuring Gunicorn in the Gunicorn project’s documentation.

  • The Django project itself is located at /home/django/django_project.

    If you rename the Django project folder, you will also need to make two configuration file updates: in the Nginx configuration, change the path to your static files; and in the Gunicorn Systemd file, update the WorkingDirectory, name, and pythonpath.

When the Droplet is running, you can immediately start using Django.

Create a Django App

To get started with a basic Django app, log into the server as root. Make sure to substitute the Droplet’s IP address.

ssh root@use_your_droplet_ip

Once you’re connected, switch to the django user, move into the project directory, and create a new app called example. This will create a new directory named example in the folder django_project.

su django
cd /home/django/django_project
python startapp example

From here, create a view by editing the example/ file. For example, using the following code in will tell Django to return Hello, world! This is our first view. as an HTTP response.

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world! This is our first view.")

Next, connect the view you just created to a URL by adding the two highlighted lines below to django_project/ These lines import the view and sets it to the default URL.

from django.conf.urls import include, url
from django.contrib import admin
from example import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^admin/', include(,

Log out of the django user and return to the root shell. Then, as root, restart the project.

systemctl restart gunicorn.service

Now, if you reload the Droplet’s IP address in your browser, you’ll see a page with Hello, world! This is our first view.

Manage the Django Project

You can start, restart, or stop the project using the Gunicorn service. For example, to restart the project after making changes, use systemctl restart gunicorn.service.

However, while developing, it can be inconvenient to restart the server every time you make a change. In that case, you might want to use Django’s built-in development server, which automatically detects changes:

systemctl stop gunicorn.service
python runserver

Using the development server, you can access the application through http://use_your_droplet_ip:8000 in a browser. This built-in server does not offer the best performance, so it’s best practice to use the Gunicorn service for production.

API Creation

In addition to creating a Droplet from the Django One-Click application using the control panel, you can also use the DigitalOcean API.

You can list all One-Click application images using the API. As an example, to create a 4GB Django Droplet in the SFO2 region, you can use the following curl command. You’ll need to either save your API access token to an environment variable or substitute it into the command below.

curl -X POST -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer '$TOKEN'' -d \
    '{"name":"choose_a_name","region":"sfo2","size":"4gb","image":"django-18-04"}' \

Next Steps

You’re ready to start working with Django. From here, you can:

  • Give sudo privileges to your user, lock down root login, and take other steps to make the Droplet ready for production.

  • Use Fabric to automate deployment and other administration tasks.

  • Check out the official Django project documentation.