Skip to content

Commit

Permalink
Merge pull request #31 from dishansa/main
Browse files Browse the repository at this point in the history
Replace hardcoded sensitive data with environment variables
  • Loading branch information
joshaber authored Nov 15, 2023
2 parents 0f90517 + 908f97d commit cd5c033
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"waitFor": "onCreateCommand",
"updateContentCommand": "pip install -r requirements.txt && python manage.py migrate",
"postCreateCommand": "",
"postCreateCommand": "cp .env.example .env",
"postAttachCommand": {
"server": "python manage.py runserver"
},
Expand Down
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY=my_secret_key
DEBUG=True

# ALLOWED_HOSTS=yourdomain.com,anotherdomain.com (Each host is separated by a comma)
ALLOWED_HOSTS=*

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=""
DB_USERNAME=""
DB_PASSWORD=""
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
db.sqlite3
__pycache__/
staticfiles/
.env/
.env
venv/
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ To collect static files:
```python
python manage.py collectstatic
```

To run this application:

```python
Expand Down
9 changes: 6 additions & 3 deletions hello_world/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"""
import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()

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

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

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

ALLOWED_HOSTS = []
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',')

if 'CODESPACE_NAME' in os.environ:
codespace_name = os.getenv("CODESPACE_NAME")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Django==4.1.13
django-browser-reload==1.6.0
python-dotenv==1.0.0

0 comments on commit cd5c033

Please sign in to comment.