Skip to content

Commit 9df6771

Browse files
committed
more fixes to config
1 parent 40d20a8 commit 9df6771

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

samples/django-postgres/README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
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!
66

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-
107
## Prerequisites
118

129
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
@@ -28,10 +25,29 @@ For this sample, you will need to provide the following [configuration](https://
2825
> 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.
2926
3027
### `POSTGRES_PASSWORD`
28+
29+
The password for the PostgreSQL database.
30+
3131
```bash
3232
defang config set POSTGRES_PASSWORD
3333
```
3434

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+
3551
## Deployment
3652

3753
> [!NOTE]

samples/django-postgres/app/crm_platform/settings.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
2222

2323
# SECURITY WARNING: keep the secret key used in production secret!
24-
SECRET_KEY = 'django-insecure-^0jq%7b(%aj$j@n0_$gk@#73&z#t%4o#klquddg1e1hdal^9!s'
24+
SECRET_KEY = os.getenv('SECRET_KEY')
2525

26-
# SECURITY WARNING: don't run with debug turned on in production!
27-
DEBUG = True
26+
if not SECRET_KEY:
27+
raise ValueError("No SECRET_KEY environment variable set!")
2828

29-
ALLOWED_HOSTS = ['*']
29+
# SECURITY WARNING: don't run with debug turned on in production!
30+
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
3031

31-
CSRF_TRUSTED_ORIGINS = [
32-
'https://*.defang.dev',
33-
'http://localhost:8000',
34-
]
32+
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split(',')
3533

3634
# Application definition
3735

samples/django-postgres/compose.dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ services:
1717
- POSTGRES_USER=django
1818
- POSTGRES_DB=django
1919
- POSTGRES_PASSWORD=password
20+
- SECRET_KEY=django-insecure-^0jq%7b(%aj$j@n0_$gk@#73&z#t%4o#klquddg1e1hdal^9!s
21+
- ALLOWED_HOSTS=*
2022
volumes:
2123
- "./app:/code"
2224
command: python manage.py migrate

samples/django-postgres/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ services:
2727
- POSTGRES_USER=django
2828
- POSTGRES_DB=django
2929
- POSTGRES_PASSWORD
30+
- SECRET_KEY
31+
- ALLOWED_HOSTS
3032
depends_on:
3133
- db

0 commit comments

Comments
 (0)