|
2 | 2 |
|
3 | 3 | [](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-django-template%26template_owner%3DDefangSamples)
|
4 | 4 |
|
5 |
| -This is a simple example of how to run Django on Defang. It is a simple Todo app that uses SQLite as the database. |
6 |
| - |
7 |
| -### NOTE |
8 |
| - |
9 |
| -This sample is a simple Django app that uses SQLite as the database, which will be reset every time you deploy. **It is not production-ready**. For production use cases, you should check out the Django + Postgres sample. |
| 5 | +This sample is a simple Django to-do app that uses SQLite as the database, which will be reset every time you deploy. **It is not production-ready**. For production use cases, you should check out the Django + Postgres sample. |
10 | 6 |
|
11 | 7 | The app includes a management command which is run on startup to create a superuser with the username `admin` and password `admin`. This means you can login to the admin interface at `/admin/` and see the Django admin interface without any additional steps. The `example_app` is already registered and the `Todo` model is already set up to be managed in the admin interface.
|
12 | 8 |
|
13 | 9 | The Dockerfile and compose files are already set up for you and are ready to be deployed. Serving is done using [Gunicorn](https://gunicorn.org/) and uses [WhiteNoise](https://whitenoise.readthedocs.io/en/latest/) for static files. The `CSRF_TRUSTED_ORIGINS` setting is configured to allow the app to run on a `defang.dev` subdomain.
|
14 | 10 |
|
15 |
| -## Essential Setup Files |
| 11 | +## Prerequisites |
16 | 12 |
|
17 |
| -1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) to describe the basic image of your applications. |
18 |
| -2. A [docker-compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications. |
19 |
| -3. A [.dockerignore](https://docs.docker.com/build/building/context/#dockerignore-files) file to comply with the size limit (10MB). |
| 13 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 14 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 15 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
20 | 16 |
|
21 |
| -## Prerequisite |
| 17 | +## Development |
22 | 18 |
|
23 |
| -1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
24 |
| -2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) |
25 |
| - Plus, make sure that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`. |
| 19 | +To run the application locally, you can use the following command: |
| 20 | + |
| 21 | +```bash |
| 22 | +docker compose up --build |
| 23 | +``` |
| 24 | + |
| 25 | +## Configuration |
| 26 | + |
| 27 | +For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration). |
| 28 | + |
| 29 | +If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`. |
| 30 | + |
| 31 | +```bash |
| 32 | +defang config set API_KEY |
| 33 | +``` |
| 34 | + |
| 35 | +## Deployment |
| 36 | + |
| 37 | +> [!NOTE] |
| 38 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 39 | +
|
| 40 | +### Defang Playground |
| 41 | + |
| 42 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 43 | +```bash |
| 44 | +defang compose up |
| 45 | +``` |
| 46 | + |
| 47 | +### BYOC (AWS) |
26 | 48 |
|
27 |
| -## A Step-by-Step Guide |
| 49 | +If you want to deploy to your own cloud account, you can use Defang BYOC: |
28 | 50 |
|
29 |
| -1. (optional) If you are using Defang BYOC, make sure to update the `CSRF_TRUSTED_ORIGINS` setting in the `settings.py` file to include an appropriate domain. |
30 |
| -2. Open the terminal and type `defang login` |
31 |
| -3. Type `defang compose up` in the CLI |
32 |
| -4. Now your application will be launched |
| 51 | +1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`. |
| 52 | +2. Make sure to update the `CSRF_TRUSTED_ORIGINS` setting in the `settings.py` file to include an appropriate domain. |
| 53 | +3. Run in a terminal that has access to your AWS environment variables: |
| 54 | + ```bash |
| 55 | + defang --provider=aws compose up |
| 56 | + ``` |
33 | 57 |
|
34 | 58 | ---
|
35 | 59 |
|
|
0 commit comments