Django: Getting Started Transcripts
Chapter: Deploying Django Webapps
Lecture: Key and secret management
Login or purchase this course to watch this video and the rest of the course contents.
0:00 By now, you're intimately familiar with your projects settings.py file. That's where all the configuration lives.
0:08 Some of the content of that file really shouldn't be in your code repo though, especially the secret key.
0:14 You may also want to have different settings for different environments. If you've got a test server as well as a production server,
0:21 they may have different needs. For example, debug should be false in production but you might want it to be true in test.
0:27 There are a couple of ways of dealing with this situation. Some production servers will pass environment variables into your program.
0:34 You can use these to change certain settings. One thing to remember is that your settings.py is just a Python script.
0:42 It gets run by the Django framework. Most of this running is just defining variables that then get imported into the underlying configuration
0:50 but it is running this means you can put code inside of it. You know, those environment variables I just mentioned well you could read them in and
0:58 change the content of your settings.py file automatically. The trick I usually use is to do an import at the bottom of settings.py
1:05 that imports all of the content of another file. Often named local dash settings.py.
1:13 You don't commit local settings to your repo because you'll want a different one for each environment.
1:18 One way of handling this is to have a test settings and a prod settings and then when you deploy, copy them to local settings.
1:26 There are also 3rd party libraries that address this kind of configuration. I've never personally used any of them so can't speak to their value
1:33 but they are out there if you want to explore.