Django
Django is a batteries-included Python framework for building secure, database-driven applications. Use this component when you need an admin interface, ORM, and templating system out of the box. Diploi provisions the deployment pipeline so you can focus on models and views instead of infrastructure.
Add to your project
Section titled “Add to your project”Paste this entry into the components list in diploi.yaml to add Django to your project.
components: - name: Django identifier: django package: https://github.com/diploi/component-django#v6.0.7Django reference
Section titled “Django reference”What Django defines in a deployment.
Environment variables
Section titled “Environment variables”Django sets these values in every deployment.
Other components can import them with env.include as django.*.
Defaults marked generated are unique to each deployment.
Parameters are set on the deployment’s Setup tab.
Secret Key
Django Secret Key.
| Variable | Type | Default | Description |
|---|---|---|---|
SECRET_KEY |
secret | generated |
Readme
Section titled “Readme”Start a demo, no card required https://diploi.com/component/django
Getting started guide https://diploi.com/blog/hosting_django_apps
A generic Django component ready to build your Django app.
This component was kickstarted running
django-admin startproject djangoapp
and it has DEBUG=true inside settings.py by default
To secure your Django app, you must update your SECRET_KEY in settings.py
By default all Django apps use SQlite, which you must update to use your database of choice inside settings.py
Uses the official astral-sh/uv:3.13-alpine Docker image and Django
IMPORTANT
Section titled “IMPORTANT”- You must generate a new SECRET_KEY for your own application
- Remember to update the database settings inside settings.py to match your own database config
- In production you must remember to update your settings.py, by changing
DEBUG=falseand if you want to use external CDNs for your static files, you will need to update theSTATIC_ROOT - For production and development, you are free to change the app server runner, so for example, if you prefer
uwsgiyou can change it directly on the Dockerfile for production and development - To install new packages, this component uses
uv, so you can add new packages usinguv add <name-of-package>
Operation
Section titled “Operation”Getting started
Section titled “Getting started”- In the Dashboard, click Create Project +
- Under Pick Components, choose Django
- In Pick Add-ons, you can add one or multiple databases to your app
- Choose Create Repository, which will generate a new GitHub repo
- Now click Launch Stack
Development
Section titled “Development”Will run uv sync for pyproject.toml or uv pip install -r requirements.txt for requirements.txt
when component is first initialized, and uv run python manage.py runserver 0.0.0.0:8000 when deployment is started.
Production
Section titled “Production”To get all static files, the image runs the command:
uv run --locked --no-dev python manage.py collectstatic --noinput to get all static files.
Lastly, the image will start the production server with the command:
uv run gunicorn djangoapp.wsgi:application --bind 0.0.0.0:8000 --workers 3 --log-level info
Common tasks (using uv)
Section titled “Common tasks (using uv)”-
Create a superuser
uv run python manage.py createsuperuser -
Run migrations
uv run python manage.py migrate -
Switch the database to Postgres instead of SQLite
- Install the Postgres driver (already present in
pyproject.toml, but if missing runuv add "psycopg2-binary"). - In
djangoapp/settings.py, setDATABASES["default"]to read fromDATABASE_URL(e.g. usingenv.dj_db_urlifenvirons[django]is installed). A typical value:
postgres://postgres:postgres@postgres.postgres:5432/app - Export
DATABASE_URLin your environment (or add to.env), then runuv run python manage.py migrate.
- Install the Postgres driver (already present in
-
Adjust CSRF trusted origins
Indjangoapp/settings.py, the list comes fromCSRF_TRUSTED_ORIGINSenv var. Add hosts as a comma-separated list, e.g.:
export CSRF_TRUSTED_ORIGINS="https://example.com,https://admin.example.com"
After updating, restart the app so Django picks up the new origins.