Question

App Platform for Django App

How do you deploy a Django application on the App platform? Specifically, how do you add/configure Nginx to serve static files?


Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

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