Aman Xavier

Tips and tools · 2 min read · 8 October 2026

7 Django settings I change on every new project

The default settings.py is fine for a tutorial. These are the seven changes I make before writing any real code.

django-admin startproject gives you a settings file that works on your laptop and nowhere else. These are the changes I make on day one, before the first model.

1. A custom user model, before the first migration

Changing the user model later is painful. Doing it now costs two minutes, even if it's empty.

python
# accounts/models.py
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    pass

# settings.py
AUTH_USER_MODEL = "accounts.User"

2. Secrets and debug from the environment

Never commit SECRET_KEY, and never let DEBUG=True reach production by accident.

python
import os

SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
DEBUG = os.environ.get("DJANGO_DEBUG", "false").lower() == "true"

3. ALLOWED_HOSTS from the environment

python
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "localhost").split(",")

4. The database from one URL

With dj-database-url, one variable configures the whole database, and it matches what most hosts give you.

python
import dj_database_url

DATABASES = {"default": dj_database_url.config(default="sqlite:///db.sqlite3")}

5. Your time zone, with USE_TZ on

Store everything in UTC and show it in local time. For products in India:

python
TIME_ZONE = "Asia/Kolkata"
USE_TZ = True

6. Static files that work in production

WhiteNoise lets Django serve its own static files efficiently, so you don't need a separate setup for CSS and the admin.

python
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")

7. Settings for running behind a proxy

If Nginx, Caddy or your host handles HTTPS, Django needs to know, or forms and redirects break in confusing ways.

python
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
CSRF_TRUSTED_ORIGINS = ["https://yourdomain.com"]

if not DEBUG:
    SESSION_COOKIE_SECURE = True
    CSRF_COOKIE_SECURE = True

Then check it

Django ships with a checker for exactly this. Run it before every first deploy:

bash
python manage.py check --deploy

Work with me

Two ways to work together

If you run a business in Tricity

XavierStack builds websites, apps and booking systems for local businesses. That's the better door for you.

Go to xavierstack.com

If you're outside India

I take a few remote projects at a time. Django, Laravel, React, Next.js, and deployment, built end to end by the person who'll actually maintain it. I've shipped two live marketplaces, so I know what breaks once real users show up.

Projects start at $150. Also open to remote full-stack roles.

Tell me what you're building