Configuration
All settings are defined via CloudflareConfig — a Pydantic v2 model that validates credentials at startup.
Full Reference
from django_cfg import CloudflareConfig
class MyConfig(DjangoConfig):
cloudflare: CloudflareConfig = CloudflareConfig(
enabled=True,
account_id="${CF_ACCOUNT_ID}",
api_token="${CF_API_TOKEN}",
d1_database_id="${CF_D1_DATABASE_ID}",
sync_users=True, # sync CustomUser on post_save
sync_batch_size=500, # rows per batch in bulk sync
d1_plan="free", # "free" or "paid"
d1_limit_warn_pct=80, # warn at 80% of daily limit
telegram_alerts_enabled=False, # Telegram on critical monitor events
telegram_batch_interval_sec=60,
telegram_alert_on_new=True,
)Fields
enabled
Default: False
Enables the entire module. When False, no signals are connected and is_ready() returns False. All dependent modules (e.g. django_monitor) silently no-op.
account_id
Required when enabled=True
Your Cloudflare Account ID. Found in the Cloudflare dashboard → right sidebar.
CF_ACCOUNT_ID=abc123...api_token
Required when enabled=True
API token with D1:Edit permission. Create at Cloudflare dashboard → My Profile → API Tokens.
CF_API_TOKEN=your-tokend1_database_id
Required when enabled=True
UUID of the D1 database to use. Found in Cloudflare dashboard → Workers & Pages → D1.
CF_D1_DATABASE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxsync_users
Default: True
When enabled, a post_save signal on CustomUser triggers an RQ task that upserts the user into the D1 users table.
Set to False to disable automatic user sync (manual sync via cf_sync_users still works).
sync_batch_size
Default: 500 (range: 1–2000)
Number of users per batch when running full_sync_users() (bulk sync command).
d1_plan
Default: "free" (choices: "free", "paid")
Cloudflare D1 billing plan. Affects daily usage limits enforced by the usage tracker:
"free"— 5 million reads / 100 000 writes per day"paid"— unlimited (no enforcement)
d1_limit_warn_pct
Default: 80 (range: 0–100)
Log a WARNING when daily D1 usage exceeds this percentage of the plan limit. Set to 0 to disable warnings. Ignored when d1_plan="paid".
telegram_alerts_enabled
Default: False
Enables Telegram notifications from django_monitor for critical events:
UNHANDLED_EXCEPTIONRQ_FAILURESLOW_QUERY(threshold > 5s)
Requires TelegramConfig to also be configured in DjangoConfig.
telegram_batch_interval_sec
Default: 60 (min: 10)
Seconds between batched Telegram alert flushes. Alerts are queued and sent together to avoid flooding.
telegram_alert_on_new
Default: True
When True, flush the batch immediately when a new error fingerprint appears (first occurrence), regardless of the batch interval.
Startup Validation
If enabled=True but any of account_id, api_token, or d1_database_id is empty, Django will fail at startup with a descriptive error:
ValueError: django_cf: enabled=True but missing required fields: ['api_token'].
Set via env vars CF_ACCOUNT_ID / CF_API_TOKEN / CF_D1_DATABASE_ID.Checking Status
python manage.py cf_statusOutputs whether the module is ready, credentials are set, and the last sync timestamp.
See Also
- Overview — Architecture and quick start
- User Sync — Sync flow details
- Monitor Configuration — Monitor-specific settings
TAGS: django_cf, configuration, cloudflare-d1, credentials DEPENDS_ON: [django-cf/overview]