|
| 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 | +## Prerequisites |
| 8 | + |
| 9 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 10 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider 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 up --build |
| 19 | +``` |
| 20 | + |
| 21 | +## Configuration |
| 22 | + |
| 23 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
| 24 | + |
| 25 | +> 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. |
| 26 | +
|
| 27 | +### `POSTGRES_PASSWORD` |
| 28 | + |
| 29 | +The password for the PostgreSQL database. |
| 30 | + |
| 31 | +```bash |
| 32 | +defang config set POSTGRES_PASSWORD |
| 33 | +``` |
| 34 | + |
| 35 | +### `SECRET_KEY` |
| 36 | + |
| 37 | +The secret key is used to secure the Django application. |
| 38 | + |
| 39 | +```bash |
| 40 | +defang config set SECRET_KEY |
| 41 | +``` |
| 42 | + |
| 43 | +### `ALLOWED_HOSTS` |
| 44 | + |
| 45 | +The allowed hosts for the Django application. (i.e. the domain your app runs on) |
| 46 | + |
| 47 | +```bash |
| 48 | +defang config set ALLOWED_HOSTS |
| 49 | +``` |
| 50 | + |
| 51 | +## Deployment |
| 52 | + |
| 53 | +> [!NOTE] |
| 54 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 55 | +
|
| 56 | +### Defang Playground |
| 57 | + |
| 58 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 59 | +```bash |
| 60 | +defang compose up |
| 61 | +``` |
| 62 | + |
| 63 | +### BYOC (AWS) |
| 64 | + |
| 65 | +If you want to deploy to your own cloud account, you can use Defang BYOC: |
| 66 | + |
| 67 | +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`. |
| 68 | +2. Run in a terminal that has access to your AWS environment variables: |
| 69 | + ```bash |
| 70 | + defang --provider=aws compose up |
| 71 | + ``` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +Title: Django & PostgreSQL |
| 76 | + |
| 77 | +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. |
| 78 | + |
| 79 | +Tags: Django, PostgreSQL, Python, SQL |
| 80 | + |
| 81 | +Languages: python |
0 commit comments