How do you deploy a Django application on the App platform? Specifically, how do you add/configure Nginx to serve static files?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello @idiallo
Yes, it’s possible to host a Django app in App Platform. We have a sample Django app in our GitHub repo which you can consider as an example and make necessary changes in your app:
https://github.com/digitalocean/sample-django
Please note that at least one of the requirements.txt, Pipfile, and setup.py must be located in the root directory of the repo.
Here’s the documentation for more information: https://www.digitalocean.com/docs/app-platform/languages-frameworks/python/
Static files are served using global CDN and there is no specific configuration done in the webserver for static files.
Cheers,
Dikshith
Your setup does not include Nginx at all. Can you run a prod application with only Gunicorn?
This may help as well; I put together an app spec YAML that models a Django app with a service, static site for staticfiles, migration job, and DB:
name: sample-django
services:
- name: server
github:
repo: digitalocean/sample-django
branch: static
deploy_on_push: true
run_command: python manage.py runserver 0.0.0.0:${PORT:-8080}
envs:
- key: DISABLE_COLLECTSTATIC
value: "1"
scope: BUILD_TIME
- key: DATABASE_URL
value: "${db.DATABASE_URL}"
scope: RUN_TIME
- key: DJANGO_ALLOWED_HOSTS
value: "${APP_DOMAIN}"
scope: RUN_TIME
jobs:
- name: migrate
kind: PRE_DEPLOY
github:
repo: digitalocean/sample-django
branch: static
deploy_on_push: true
run_command: python manage.py migrate
envs:
- key: DISABLE_COLLECTSTATIC
value: "1"
scope: BUILD_TIME
- key: DATABASE_URL
value: "${db.DATABASE_URL}"
scope: RUN_TIME
static_sites:
- name: static
github:
repo: digitalocean/sample-django
branch: static
deploy_on_push: true
# This happens as part of the Python/DJango buildpack:
# build_command: python manage.py collectstatic --noinput
output_dir: staticfiles
routes:
- path: /static
databases:
# Create a new dev DB:
- name: db
engine: PG
version: "12"
# Or bring an existing DB:
# - name: db
# production: true
# cluster_name: mydb
# engine: PG
# version: "12"
This can be submitted using doctl with:
doctl apps create --spec .do/app.yaml
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.