|
| 1 | +# Django Channels & Redis & Postgres |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-django-channels-redis-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This sample demonstrates how to get Django Channels up and running with Redis and Postgres both managed by Defang. It demonstrates how to do this with a simple chat application. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 10 | +2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account |
| 11 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 12 | + |
| 13 | +## Development |
| 14 | + |
| 15 | +To run the application locally, you can use the following command: |
| 16 | + |
| 17 | +```bash |
| 18 | +docker compose -f compose.dev.yaml up |
| 19 | +``` |
| 20 | + |
| 21 | +This will start the Django server, Redis, and Postgres and mounts your Django app so you get live reloading. You can access the Django server at `http://localhost:8000`. |
| 22 | + |
| 23 | +## Configuration |
| 24 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you. |
| 25 | + |
| 26 | +### `SECRET_KEY` |
| 27 | +The secret key for your Django application. You can generate a new one by running `python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'`. A default, insecure key is used if this is not set, but you should set it for a production deployment. |
| 28 | + |
| 29 | +### `POSTGRES_PASSWORD` |
| 30 | +The password for your Postgres database. You need to set this before deploying for the first time. |
| 31 | + |
| 32 | +## Deploying |
| 33 | + |
| 34 | +1. Open the terminal and type `defang login` |
| 35 | +2. Use the [`defang config`](https://docs.defang.io/docs/concepts/compose#configuration) command to setup environment variables. |
| 36 | +3. Type `defang compose up` in the CLI. |
| 37 | +4. Your app will be running within a few minutes. |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +Title: Django Channels & Redis & Postgres |
| 42 | + |
| 43 | +Short Description: A basic configuration of Django Channels with Redis and Postgres demonstrating a simple chat application. |
| 44 | + |
| 45 | +Tags: Django, Channels, Redis, Postgres, Chat, Application |
| 46 | + |
| 47 | +Languages: Python |
0 commit comments