{"id":20698206,"url":"https://github.com/fly-apps/hello-django-postgres","last_synced_at":"2026-03-27T04:45:48.137Z","repository":{"id":89110029,"uuid":"597056863","full_name":"fly-apps/hello-django-postgres","owner":"fly-apps","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-14T18:29:12.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-14T01:52:33.334Z","etag":null,"topics":["django","django4-1","flyio","gunicorn","postgres","psycopg2","venv"],"latest_commit_sha":null,"homepage":"https://hello-django-postgres.fly.dev/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fly-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-03T14:33:03.000Z","updated_at":"2023-04-25T08:21:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7cf464b-55f8-486a-a73c-3949cf8f8527","html_url":"https://github.com/fly-apps/hello-django-postgres","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fhello-django-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fhello-django-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fhello-django-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fhello-django-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fly-apps","download_url":"https://codeload.github.com/fly-apps/hello-django-postgres/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809032,"owners_count":21164895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django4-1","flyio","gunicorn","postgres","psycopg2","venv"],"created_at":"2024-11-17T00:23:29.970Z","updated_at":"2026-03-27T04:45:43.103Z","avatar_url":"https://github.com/fly-apps.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## HelloDjangoPostgres!\n\nThis is an example project demonstrating how to deploy a Django application with Postgres on Fly.io.\n\n### Local Development\n\nThe environment variables are stored in the `.env` file.\n\nDuplicate `.env.dist` file and rename it to `.env`. Update the environment variables:\n```\nSECRET_KEY=\u003cyour-generated-django-secure-super-secret-key\u003e\nDEBUG=True\nDATABASE_URL=postgres://\u003cuser\u003e:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e/\u003cdb\u003e\n```\n\n\u003e The default `DATABASE_URL` is `postgres://postgres:postgres@localhost:5432/hello_django` (check `hello_django/settings.py`).\n\n---\n## Getting started\n\n[flyctl](https://fly.io/docs/hands-on/install-flyctl/) is the command-line utility provided by Fly.io.\n\nIf you still don't have installed it, you can follow the [instructions here](https://fly.io/docs/hands-on/install-flyctl/) to install it, [sign up](https://fly.io/docs/hands-on/sign-up/) and [log in](https://fly.io/docs/hands-on/sign-in/) to Fly.io.\n\n---\n## Create and configure a new app (`fly launch`)\n\nThis simple app already contains all the basic configuration for deploying to Fly.io.\n- `Dockerfile` contain commands to build the image.\n- `.dockerignore` list of files or directories Docker will ignore during the build process.\n- `fly.toml` configuration for deployment on Fly.io.\n\n---\n#### Dockerfile\n\n`SECRET_KEY` is required when running `collectstatic`. A default `SECRET_KEY` can be generated by using the `get_random_secret_key` function provided by Django:\n```python\n# settings.py\nfrom django.core.management.utils import get_random_secret_key\n...\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = env.str('SECRET_KEY', default=get_random_secret_key())\n```\n\nAn alternative is to set a random key on `Dockerfile` for building purposes:\n```Dockerfile\n# Dockerfile\nENV SECRET_KEY \"non-secret-key-for-building-purposes\"  # \u003c-- Set SECRET_KEY for building purposes\nRUN python manage.py collectstatic --noinput\n```\n\n\n\n---\nWhen running `fly launch`, copy the existing configuration to your own app:\n\n```shell\n❯ fly launch\nAn existing fly.toml file was found for app hello-django-postgres\n? Would you like to copy its configuration to the new app? Yes\n```\n\n### Secrets\n\nDuring the `fly launch`, the necessary secrets will be set:\n- `SECRET_KEY`\n- `DATABASE_URL`\n\n## Django `SECRET_KEY`\n\n```shell\n❯ fly launch\nCreating app in /Projects/flyio/hello-django-postgres\nScanning source code\nDetected a Django app\n? Choose an app name (leave blank to generate one): hello-django-postgres\n...\nHostname: hello-django-postgres.fly.dev\nSet secrets on hello-django-postgres: SECRET_KEY  # \u003c-- SECRET_KEY is set automatically\n```\n\n## Postgres `DATABASE_URL`\n\nSet up a Postgres database during the `fly launch` step:\n```shell\n❯ fly launch\nCreating app in /Projects/flyio/hello-django-postgres\nScanning source code\nDetected a Django app\n? Choose an app name (leave blank to generate one): hello-django-postgres\n...\n? Would you like to set up a Postgresql database now? Yes  # \u003c-- You will be asked HERE\n? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk\nCreating postgres cluster in organization fly-io\nCreating app...\nSetting secrets on app hello-django-postgres-db...\nProvisioning 1 of 1 machines with image flyio/postgres:14.6\nWaiting for machine to start...\n....\nPostgres cluster hello-django-postgres-db is now attached to hello-django-postgres\nThe following secret was added to hello-django-postgres:\n  DATABASE_URL=postgres://hello_django_postgres:****@****:5432/hello_django_postgres?sslmode=disable\nPostgres cluster hello-django-postgres-db is now attached to hello-django-postgres  # \u003c-- postgres cluster attached to the app\n```\n\n\u003e Important: During this step, save your credentials in a secure place - you won't be able to see them again!\n\nYour postgres cluster will be automatically attached to your app.\n\n## `ALLOWED_HOSTS` and `CSRF_TRUSTED_ORIGINS`\n\nBefore we can deploy it, make sure to update `ALLOWED_HOSTS` and `CSRF_TRUSTED_ORIGINS` in `hello_django/settings.py` with the chosen/generated app name on Fly.io. \n\n```python\nALLOWED_HOSTS = ['127.0.0.1', 'localhost', '\u003cyour-app-name\u003e.fly.dev']\nCSRF_TRUSTED_ORIGINS = ['https://\u003cyour-app-name\u003e.fly.dev']\n```\n\nYour Django app is now ready to be deployed!\n\n---\n## Deploy (`fly deploy`)\n\nOnce all the previous steps are done, you can deploy your app:\n```shell\n❯ fly deploy\n==\u003e Verifying app config\n--\u003e Verified app config\n==\u003e Building image\n...\n 1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]\n--\u003e v0 deployed successfully\n```\n\nYour app is now up and running!\n\n```shell\n❯ fly open\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fhello-django-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffly-apps%2Fhello-django-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fhello-django-postgres/lists"}