5 ms·
Just use a settings file. I use settings overrides by putting local_settings.py in my .gitignore and then adding this to the bottom of my settings.py: https://g
by j2labs 15y ago
Just use a settings file. I use settings overrides by putting local_settings.py in my .gitignore and then adding this to the bottom of my settings.py: https://github.com/j2labs/microarmy/blob/master/settings.py#L52 https://github.com/j2labs/microarmy/blob/master/settings.py#...
- astrofinch 15y agoWhy are you masking errors from that import?
- tawhaki 15y agoI assume it is so that the default values are used if no local_settings.py file exists, instead of aborting the program with an uncaught ImportError.
- pjscott 15y agoIf so, then for the benefit of any Python newbies here: "except ImportError" is the idiomatic way to handle this situation, it it clearly communicates intent, and prevents masking legitimate errors. One fairly common pattern is to try to import one module, and if it's not installed, to go for a backup. For example, if I need to parse JSON, the simplejson library is significantly faster than the (completely API-compatible) standard library "json" module: try: import simplejson as json except ImportError: import json I'm pretty sure I've seen those exact four lines of code in the internals of Tornado and Flask, among others.
- mdonahoe 15y agoexplicit is better than implicit He should explicitly catch the ImportError