-
Notifications
You must be signed in to change notification settings - Fork 0
/
31-0-django-environ.sh
33 lines (25 loc) · 1.16 KB
/
31-0-django-environ.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Install django-environ
poetry add 'django-environ=*'
# Patch the settings.py file with configurable stuff using django-environ
sed -i "/from pathlib import Path/a import environ" "$DJANGO_PROJECT_NAME/settings.py"
sed -i "/BASE_DIR = /a env = environ.Env()\nenv.read_env(str(BASE_DIR / '.env'))" "$DJANGO_PROJECT_NAME/settings.py"
sed -i "s/SECRET_KEY = .*/SECRET_KEY = env.str('SECRET_KEY')/" "$DJANGO_PROJECT_NAME/settings.py"
sed -i "s/DEBUG = .*/DEBUG = env.bool('DEBUG', default=False)/" "$DJANGO_PROJECT_NAME/settings.py"
sed -i "s/ALLOWED_HOSTS = .*/ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[])/" "$DJANGO_PROJECT_NAME/settings.py"
sed -i "/DATABASES = {/,/^}/c DATABASES = {\n 'default': env.db('DATABASE_URL')\n}" "$DJANGO_PROJECT_NAME/settings.py"
cat <<EOF > example.env
SECRET_KEY=your_secret_key
DEBUG=True
DATABASE_URL=postgresql://localhost/$POETRY_PROJECT_NAME
EOF
# Add .env to .gitignore
echo ".env" >> .gitignore
# describe in the README
cat <<EOF >> "README.md"
## Environment Variables
Configure quick-start env vars
cp example.env .env
EOF
poetry run isort .
git add --all
git commit -m "Configure Django settings with django-environ"