#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. In the main app, mysite, there's a setting.py file which administers a lot of settings.
0:11 And in this video, we will do three important things we set the secret key and debug in the environment to venv/bin/activate.
0:20 We add a new quotes app to the installed apps and we define a central template folder, mysite templates which we have to add to the templates constant.
0:30 And we will see that later that's where the base template will live. So, going to settings, and notice that there are
0:39 a couple of security warnings I want to address first. The secret key should never be hard coded so we're going to load that from the environment
0:48 and debug set to True which is fine now. But when you deploy the app, it that be False so it's better to control the app from the environment
0:55 and not hard code it like is done here. So let's load it from my environment.
1:22 And, notice the difference, if secret key is not available it will just crash which is good and for debug, if it's not available I set it to false
1:33 which you can do with the get method on a dictionary. So if debug is not defined, in my environment it is just set to False by default.
1:42 A large host will probably also limit the hosts that can connect to the app but that's more relevant when we deploy the app
1:48 so I'm leaving that empty for now. To load those variables, I'm going to go into venv/bin/activate, which is the activation script
1:58 of my virtual environment so when I enable the virtual environment this activate script is called. So the variables I store in this script
2:08 will be accessible in my environment. So go down and then do export SECRET_KEY. And export DEBUG=True for now because we're still building the app
2:26 so want to see any error that occurs. Secondly, in the installed apps we see all the stuff that came with Django.
2:38 When we build new apps, as we did with quotes we need to add it here so that's a manual step that's always required. And lastly, on the templates
2:53 we have DIRS and APP_DIRS. APP_DIRS means if we follow a convention with the templates in the apps, they will be found. And we will see that later.
3:04 But I will have a central template directory which I can actually make now. Which is mysite and you see it's not there
3:15 so I'm going to make mysites templates and later we're going to create a base.html which I can already touch.
3:24 Now this directory is no going to be found yet. Actually I was testing that and what happens is if you don't set that in dirs
3:33 you get a template that does not exist ever. So, to prevent that, I'm going to set it here and I'm going to join that base here
3:46 which is to find at the top. And going to join that with mysite templates. So again, this is to make sure that the base template
4:02 we will define later, will be found. And that's it for now. These are the settings I usually set directly when starting a Django project.


Talk Python's Mastodon Michael Kennedy's Mastodon