You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: units/django/4/database-orm-and-models.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,6 +315,27 @@ You can try manipulating the models using the shell and can refresh the browser
315
315
316
316
Awesome. Hope, this tutorial explained well what Models in Django are and how it abstracts away the complexities of the underlying database.
317
317
318
+
## ProTip
319
+
In our above tutorial we've stored our database credentials directly in our `settings.py` which is not a good practice if we're going to check in that file in our git repository.
320
+
321
+
It's a recommended practice to load your credentials or deployment specific configurations using environment variables or some other gitignored file and just reference them in your `settings.py` file something like this:
322
+
323
+
```python
324
+
DATABASES= {
325
+
'default': {
326
+
'ENGINE': 'django.db.backends.postgresql',
327
+
'NAME': os.environ.get('DB_NAME'),
328
+
'USER': os.environ.get('DB_USER'),
329
+
'HOST': os.environ.get('DB_HOST'),
330
+
'PORT': os.environ.get('DB_PORT'),
331
+
'PASSWORD': os.environ.get('DB_PASSWORD'),
332
+
}
333
+
}
334
+
```
335
+
You can take this [sample](https://github.com/kabirbaidhya/django-todoapp/blob/step-16/todoapp/settings.py#L79-L88) as an example.
336
+
Here I've made use of a python package `python-dotenv` to load environment variables from a `.env` file.
337
+
338
+
## Source Code
318
339
Check the full source code [here](https://github.com/kabirbaidhya/django-todoapp/tree/step-16).
0 commit comments