8000 Merge pull request #31 from dishansa/main · github/codespaces-django@cd5c033 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd5c033

Browse files
authored
Merge pull request #31 from dishansa/main
Replace hardcoded sensitive data with environment variables
2 parents 0f90517 + 908f97d commit cd5c033

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"waitFor": "onCreateCommand",
77
"updateContentCommand": "pip install -r requirements.txt && python manage.py migrate",
8-
"postCreateCommand": "",
8+
"postCreateCommand": "cp .env.example .env",
99
"postAttachCommand": {
1010
"server": "python manage.py runserver"
1111
},

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SECRET_KEY=my_secret_key
2+
DEBUG=True
3+
4+
# ALLOWED_HOSTS=yourdomain.com,anotherdomain.com (Each host is separated by a comma)
5+
ALLOWED_HOSTS=*
6+
7+
DB_HOST=127.0.0.1
8+
DB_PORT=3306
9+
DB_DATABASE=""
10+
DB_USERNAME=""
11+
DB_PASSWORD=""

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
db.sqlite3
22
__pycache__/
33
staticfiles/
4-
.env/
4+
.env
55
venv/

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ To collect static files:
1010
```python
1111
python manage.py collectstatic
1212
```
13-
1413
To run this application:
1514

1615
```python

hello_world/settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"""
1212
import os
1313
from pathlib import Path
14+
from dotenv import load_dotenv
15+
16+
load_dotenv()
1417

1518
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1619
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -20,12 +23,12 @@
2023
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
2124

2225
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = "django-insecure-rc@04_mry_3-$@2sq$b9%-9jp6q2eyxf4bsw9&&esj++aw&r)p"
26+
SECRET_KEY = os.getenv("SECRET_KEY")
2427

2528
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
29+
DEBUG = os.getenv("DEBUG")
2730

28-
ALLOWED_HOSTS = []
31+
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',')
2932

3033
if 'CODESPACE_NAME' in os.environ:
3134
codespace_name = os.getenv("CODESPACE_NAME")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Django==4.1.13
22
django-browser-reload==1.6.0
3+
python-dotenv==1.0.0

0 commit comments

Comments
 (0)
0