The short answer
To deploy a Django app, give your coding agent the sentence below. Antideploy finds Django in your requirements, creates a Postgres database, runs python manage.py migrate before the new version goes live, and starts the app with gunicorn if it is in your requirements. Without gunicorn it uses Django's built-in server and warns you.
Say this to your coding agent
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
What Antideploy detects
-
Django. Detected from
djangoinrequirements.txtorpyproject.toml. -
The start command. With
gunicorn,waitressoruwsgiin your requirements:gunicorn yourproject.wsgi --bind 0.0.0.0:$PORT, where the project name comes from yoursettings.py. Without one:python manage.py runserver 0.0.0.0:$PORT, and a warning that this server is meant for demos, not real traffic. -
The database and migrations. Django needs a database, so Antideploy creates Postgres, and runs
python manage.py migratebefore the new version goes live. A failed migration fails the deploy. -
The port. It starts the app with
PORTset. -
The Python version. From
.python-version,runtime.txtorrequires-pythoninpyproject.toml.
Settings Django needs
Three settings in settings.py matter online. Django does not read DATABASE_URL by itself.
import os
import dj_database_url
ALLOWED_HOSTS = [".antideploy.app"]
CSRF_TRUSTED_ORIGINS = ["https://*.antideploy.app"]
DATABASES = {
"default": dj_database_url.config(env="DATABASE_URL", conn_max_age=600),
}
ALLOWED_HOSTSmust include your address, or Django answers every request with an error. Add your own domain too, if you attach oneCSRF_TRUSTED_ORIGINSneeds yourhttps://address, or form posts are refused- Add
dj-database-urlto your requirements, or build the connection from thePG*variables - Keep
SECRET_KEYout of your code. If your code readsSECRET_KEY, Antideploy generates one for you
Static files
Django does not serve its own static files in production. A common way is WhiteNoise: add it to your requirements and middleware, and run collectstatic during your build. Files that people upload belong in a bucket, not on the app's disk.
Step by step
-
Add gunicorn and the database package
List
gunicornanddj-database-urlinrequirements.txt. -
Paste the sentence and approve one link
Your agent creates the app and the database, writes the connection details into your
.envwithout printing them, and builds against the real database. -
Deploy and open the link
Antideploy installs your requirements, runs
python manage.py migrate, starts the app and checks that it answers. Your agent tells you the address.