App Platform is a Platform-as-a-Service (PaaS) offering that allows developers to publish code directly to DigitalOcean servers without worrying about the underlying infrastructure.
The Python buildpack applies to this sample app. See the Python buildpack overview for more information about its configuration options and limitations.
This page is automatically generated from https://github.com/digitalocean/sample-django/blob/main/README.md.
These steps will get this sample Django application running for you using DigitalOcean.
This application is the standard Django Polls Tutorial with an added page at /
.
This app uses a Postgres database by default. If you want to change this to use
a local sqlite db (this will not persist deployments) then you’ll need to set
an environment variable specified below.
Note: Following these steps will result in charges for the use of DigitalOcean services
To use all the features of App Platform, you need to be running against your own copy of this application. To make a copy, click the Fork button above and follow the on-screen instructions. In this case, you’ll be forking this repo as a starting point for your own app (see Github documentation to learn more about forking repos.
After forking the repo, you should now be viewing this README in your own github org (e.g. https://github.com/<your-org>/sample-django
)
<your-org>/sample-django
) and click Next.DEBUG
to True
DJANGO_ALLOWED_HOSTS
to ${APP_DOMAIN}
to set the allowed_hosts
setting of your app to the default domain provided by DigitalOcean.DATABASE_URL
to ${<YOUR_DB_NAME>.DATABASE_URL}
. You will set the database name in a next step. For simplicity, just name it db
so the example would look like ${db.DATABASE_URL}
mysite
. So the modified command would be gunicorn --worker-tmp-dir /dev/shm mysite.wsgi
.db
. You can also connect an existing DBaaS instance if you choose.python manage.py migrate
to perform the initial database migration. After setup, you may need to migrate the database again if updated. For this reason, we recommend setting up a pre-deploy Job to migrate the database, automated to run before each deployment. This method also ensures that the migration happens successfully before serving traffic. If it fails, the old version of the service remains active instead.python manage.py createsuperuser
and follow the prompts to create a super user to access at /admin
.Many of the Django settings necessary to have an app run on App Platform have been exposed as environment variables. Below is a list and what they do
False
.127.0.0.1,localhost
. Can be a comma deliminated list. For more information about allowed_hosts
view the django documentation.False
therefore using the Postgres dbFalse
.As long as you left the default Autodeploy option enabled when you first launched this app, you can now make code changes and see them automatically reflected in your live application. During these automatic deployments, your application will never pause or stop serving request because the App Platform offers zero-downtime deployments.
Here’s an example code change you can make for this app:
You can learn more about the App Platform and how to manage and update your application at https://www.digitalocean.com/docs/apps/.
When you no longer need this sample application running live, you can delete it by following these steps:
This will delete the app and destroy any underlying DigitalOcean resources
Note: If you don’t delete your app, charges for the use of DigitalOcean services will continue to accrue.