Python for Entrepreneurs Transcripts
Chapter: Build web apps with Pyramid: Part 1
Lecture: Building Block: config
0:01 Another key building block is configuration. In any real web application you are going to have specific details
0:08 that either you want to keep out of code because you want to make them editable and configurable, or more likely you want to have different versions
0:15 based on where your app is running. Is it being used in development? Is it being run in production? Things like that.
0:23 So here is a standard configuration file, this will be in development.ini or production.ini, take your pick;
0:28 you can make these files up and hand then off to the web server. Notice here that we have two values that we've added,
0:35 we've added db_file, which is going to be a relative path to a SQLite database file, and api_key. Maybe this is our MailChimp or Stripe API key.
0:45 For whatever reason, our application is going to need this data to work. So how do we get to it?
0:50 Well, over in the __init__ method we saw we have this "main" and it creates a configuration, we've already used this for a routing
0:57 but it also has other functions, for example we can say get us the settings, which are the settings out of this section of ini file
1:06 and then we can do things like just say get the db_file or get the api_key,
1:10 config settings as a dictionary and it's populated with all the values that you see here.
1:15 Then you save this pass around your application and use it wherever you need them.