What you need before starting
- A Linux server with Python (the same version you develop with) and SSH access.
- A
requirements.txtorpyproject.tomlwith pinned dependencies. - A database (PostgreSQL is the usual choice) and a domain.
The steps, in short
- Prepare the server: your own user, firewall and updated packages.
- Create a virtual environment and install the dependencies.
- Configure for production. In Django:
DEBUG=False,ALLOWED_HOSTSwith your domain andSECRET_KEYfrom an environment variable. In FastAPI: turn off the open docs if the API is private. - Apply migrations and, in Django, run
collectstatic. - Run with an application server: Gunicorn for Django (
gunicorn project.wsgi) or Gunicorn with the Uvicorn worker for FastAPI. - Create a systemd service with automatic restart.
- Put Nginx in front to serve static files and forward the rest, and enable HTTPS.
Common mistakes
- Leaving
DEBUG=Truein production, which shows code and configuration on any error. - Committing the
SECRET_KEYor passwords to the repository. - Using SQLite with several processes and a lot of traffic.
- Forgetting
CSRF_TRUSTED_ORIGINSwhen the site is behind an HTTPS proxy.
How we help
We leave your Python application running with Gunicorn, Nginx, HTTPS and automatic deploys from your repository.