|
| 1 | +# Django & Postgres |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-django-postgres-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This template is a customer relationship management list project developed using Python Django framework, offering a starting point to help you quickly build your customer management system. We use PostgreSQL as the database. We have prepared all the essential files for deployment. By spending less than 10 minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live to the world! |
| 6 | + |
| 7 | +> [!NOTE] |
| 8 | +This sample showcases how you could deploy a full-stack application with Defang and Django. However, it deploys Postgres as a Defang service. Defang [services](https://12factor.net/processes) are ephemeral and should not be used to run stateful workloads in production as they will be reset on every deployment. For production use cases you should use a managed database like RDS, Aiven, or others. If you stick to Django's default SQLite database, your stored data will be lost on every deployment, and in some other situations. In the future, Defang will help you provision and connect to managed databases. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 13 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 14 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 15 | + |
| 16 | +## Development |
| 17 | + |
| 18 | +To run the application locally, you can use the following command: |
| 19 | + |
| 20 | +```bash |
| 21 | +docker compose up --build |
| 22 | +``` |
| 23 | + |
| 24 | +## Configuration |
| 25 | + |
| 26 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
| 27 | + |
| 28 | +> 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. |
| 29 | +
|
| 30 | +### `POSTGRES_PASSWORD` |
| 31 | +```bash |
| 32 | +defang config set POSTGRES_PASSWORD |
| 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) |
| 48 | + |
| 49 | +If you want to deploy to your own cloud account, you can use Defang BYOC: |
| 50 | + |
| 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. Run in a terminal that has access to your AWS environment variables: |
| 53 | + ```bash |
| 54 | + defang --provider=aws compose up |
| 55 | + ``` |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +Title: Django & PostgreSQL |
| 60 | + |
| 61 | +Short Description: A customer relationship management list project developed using the Python Django framework, offering a starting point to help you quickly build your customer management system. |
| 62 | + |
| 63 | +Tags: Django, PostgreSQL, Python, SQL |
| 64 | + |
| 65 | +Languages: python |
0 commit comments