Skip to content

Add template for deploying Django apps on Databricks Apps#185

Draft
tlgnr wants to merge 19 commits intodatabricks:mainfrom
tlgnr:main
Draft

Add template for deploying Django apps on Databricks Apps#185
tlgnr wants to merge 19 commits intodatabricks:mainfrom
tlgnr:main

Conversation

@tlgnr
Copy link
Copy Markdown

@tlgnr tlgnr commented Apr 10, 2026

This template deploys a simple Django todo app on Databricks Apps with Lakebase Autoscaling as the PostgreSQL database backend. It's designed to be familiar to Django developers, adding new code only where needed to interface with Databricks. The goal is for Django developers to get up and running quickly on Databricks.

tlgnr and others added 19 commits April 10, 2026 18:20
…per directory

Remove the `django-on-databricks-apps/` parent directory and promote
`django-postgres-app/` to the top level. Move `databricks.yml` and
`README.md` into the app directory and update internal references:
- databricks.yml: source_code_path from `./django-postgres-app` to `.`
- pyproject.toml: readme from `../README.md` to `README.md`
- README.md: flatten project structure listing, remove `cd` step
The add view manually checked request.method while toggle and delete
used the decorator. Replace the manual check with @require_POST for
consistency -- GET requests now return a proper 405 instead of a
silent redirect.
Set SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE to not DEBUG so
cookies are transmitted over HTTPS only in production while still
working over plain HTTP during local development.
Replace raw request.POST access with a TodoForm ModelForm for proper
validation through Django's forms framework. The form widget carries
the placeholder and required attributes so the template renders
identically.
Only write the completed column instead of all fields, avoiding
unnecessary database work and potential overwrites of concurrent
changes to other fields.
All three auth functions (authenticate, login, logout) now share a
single top-level import instead of logout being imported lazily inside
the else branch. There is no circular import risk here.
Move the helper out of config/settings.py into utils.py so both
settings and the ensure_schema management command import from a
standalone module rather than coupling to the settings file directly.
Replace uvicorn and the ASGI entry point with gunicorn and a standard
WSGI configuration. All views are synchronous so there is no benefit
from an async server; gunicorn with sync workers is the conventional
Django deployment and simplifies connection-pool reasoning.
Use Django's default of closing connections after each request. The
Lakebase backend injects short-lived OAuth tokens, so persistent
connections would go stale anyway. Closing per-request avoids that
complexity with negligible overhead for this workload.
Add double-checked locking so concurrent threads cannot both create a
WorkspaceClient. Reuses the existing _token_lock since the client is
only initialised once and the lock is uncontended at that point.
Cast to float and document that expire_time is a protobuf Timestamp
whose .seconds field gives Unix epoch seconds, matching time.time().
Align the package name with the directory name (django-postgres-app).
Accept common truthy values (true, 1, yes) regardless of case instead
of requiring the exact string "True". Defaults to False when the
environment variable is unset.
This keeps deployment docs aligned with the actual `entrypoint.sh` sequence so users run the expected `gunicorn`-based startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants