Django demo reference

The Django source is on GitHub. fly launch will provide a Dockerfile and a fly.toml config file. When you make changes to your application, you can use dockerfile-django to produce updated Dockerfiles.

How the pieces are put together:

  • The original web-dictaphone app (minus the HTML) is in the static directory, and contains icons, scripts, styles, and a web manifest; all served as static files.
  • clips/templates/clips/index.html contains the HTML template.
  • Django Models and databases is configured to use Sqlite3 as the database in development mode, and PostgreSQL in production. Access to the database is through the DATABASE_URL secret.
  • Django Storages is configured to write to the filesystem in development and Tigris in production. The following secrets are used to establish the connection: AWS_ACCESS_KEY_ID, AWS_ENDPOINT_URL_S3, AWS_REGION, AWS_SECRET_ACCESS_KEY, and BUCKET_NAME.
  • Django Channels is configured to use an in memory channel in development and Redis in production based using the REDIS_URL secret.

Key points of logic:

  • static/scripts/app.js has been modified to make server requests at various points using the Fetch API.
  • clips/views.py contains the logic to build responses to requests for the index page, and to GET, PUT, and DELETE audio clips.
  • The server side realtime implementation code is primarily in Django Channels, so all that is needed is a few lines in clips/models.py. The client side is provided by static/scripts/websocket.js. When update notifications are received, the index page is re-retrieved and the body of the DOM is replaced with new contents.
  • When the WHISPER_URL secret is set, PUT requests will cause the audio clips to be passed to the Whisper server, and responses will be used to update the PostgreSQL database. This is done using Celery. The code for this is in clips/tasks.py.