#100DaysOfWeb in Python Transcripts
Chapter: Days 45-48: Build a simple Django app
Lecture: Basic Django configuration

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's look at Django's configuration.
0:03 In the main app, mysite, there's a setting.py file
0:07 which administers a lot of settings.
0:10 And in this video, we will do three important things
0:13 we set the secret key and debug in the environment
0:17 to venv/bin/activate.
0:19 We add a new quotes app to the installed apps
0:22 and we define a central template folder, mysite templates
0:26 which we have to add to the templates constant.
0:29 And we will see that later
0:30 that's where the base template will live.
0:33 So, going to settings, and notice that there are
0:38 a couple of security warnings I want to address first.
0:42 The secret key should never be hard coded
0:44 so we're going to load that from the environment
0:47 and debug set to True which is fine now.
0:49 But when you deploy the app, it that be False
0:51 so it's better to control the app from the environment
0:54 and not hard code it like is done here.
1:01 So let's load it from my environment.
1:21 And, notice the difference, if secret key is not available
1:25 it will just crash which is good
1:28 and for debug, if it's not available
1:30 I set it to false
1:32 which you can do with the get method on a dictionary.
1:35 So if debug is not defined, in my environment
1:38 it is just set to False by default.
1:41 A large host will probably also limit
1:43 the hosts that can connect to the app
1:45 but that's more relevant when we deploy the app
1:47 so I'm leaving that empty for now.
1:51 To load those variables, I'm going to go into
1:54 venv/bin/activate, which is the activation script
1:57 of my virtual environment
1:59 so when I enable the virtual environment
2:02 this activate script is called.
2:04 So the variables I store in this script
2:07 will be accessible in my environment.
2:11 So go down and then do export SECRET_KEY.
2:19 And export DEBUG=True for now
2:23 because we're still building the app
2:25 so want to see any error that occurs.
2:32 Secondly, in the installed apps
2:34 we see all the stuff that came with Django.
2:37 When we build new apps, as we did with quotes
2:40 we need to add it here
2:41 so that's a manual step that's always required.
2:47 And lastly, on the templates
2:52 we have DIRS and APP_DIRS.
2:55 APP_DIRS means if we follow a convention
2:58 with the templates in the apps, they will be found.
3:01 And we will see that later.
3:03 But I will have a central template directory
3:07 which I can actually make now.
3:09 Which is mysite and you see it's not there
3:14 so I'm going to make mysites templates
3:18 and later we're going to create a base.html
3:21 which I can already touch.
3:23 Now this directory is no going to be found yet.
3:27 Actually I was testing that and what happens is
3:29 if you don't set that in dirs
3:32 you get a template that does not exist ever.
3:35 So, to prevent that, I'm going to set it here
3:43 and I'm going to join that base here
3:45 which is to find at the top.
3:50 And going to join that with
3:53 mysite templates.
3:58 So again, this is to make sure that the base template
4:01 we will define later, will be found.
4:03 And that's it for now.
4:04 These are the settings I usually set directly
4:07 when starting a Django project.