8. Django configuration security in production
A common mistake when deploying Django to production is leaving DEBUG=True enabled. If an application error occurs, this can expose the full stack trace, environment variables, and code snippets to users, creating a serious information leak about the application's internal structure.
The SECRET_KEY used by Django to sign sessions and tokens should be unique for each deployment and should never be committed to the code repository. Instead, set it as an environment variable in the application configuration on Saplo, separately from the source code itself.
ALLOWED_HOSTS should contain exactly the domains where the application is available, not a wildcard that allows every host. This provides basic protection against Host header injection attacks, which is especially important for applications that accept data from users on the internet.
Logically separate static files from user media (uploads), serving the application's static files through nginx and user-uploaded files through a separate mechanism with appropriate permissions. This prevents users from uploading and executing a malicious script on the server.
Updating Django itself and the Python packages listed in requirements.txt should be part of your regular workflow. Just like in the Node.js ecosystem, outdated dependencies are a common attack vector for known vulnerabilities with available fixes and are routinely found by automated vulnerability scanners.
For applications that store users' personal data, it is worth deliberately configuring session settings (expiration time, Secure and HttpOnly cookie flags). Django supports them natively, but they require explicit configuration in the project settings and do not work correctly with the default values in every scenario. Before the first production deployment, review this configuration along with the full list of Django security settings instead of discovering a missing setting only after a real security incident.