Note taking software mac free best
Iâve been going through quite a bit of changes in my life lately â and as a part of that, my home blog (not this one â the personal things) will be moving to http://www.rachelblum.com.
And since I felt like I need more experience with web frameworks in general, Iâm not sticking with my trusty wordpress. It does all the things I want it to do, but it was time to try something new: Django.
It was surprisingly easy to get started â most of my troubles came from the facts that Iâve skipped steps in the tutorials here or there, and then got flabbergasted when things didnât work. Well, itâs all sorted out so far, but thereâs one nifty trick Iâd really like to share. Django has all its settings in a settings.py file, and it needs to change depending where you deploy and what your backend database is. That doesnât work well with the idea of version control â so I modified the settings so you can get settings per machine.
At the bottom of settings.py, add the following code:
import socket
hostname = socket.gethostname().replace(â.â,â_â)
hostname = hostname.replace(â-â,â_â).lower()
exec “from config.%s import *” % hostname Â
Â
Notes
- I put all my configurations into a separate config module. I just like things clean â you can certainly keep them with the rest of your python.
- I know that
execis evil, but I really couldnât figure out how to do this with__import__instead. Any tips appreciated - The mangling of
gethostname()viareplace()gets rid of invalid characters that import canât handle. Also, itâs only split over two lines so I donât get ugly line breaks.
All those per-host files should only contain host-specific settings. With exactly one development and one production machine, thatâs certainly not too much duplication. And yet, I split it up into production.py and development.py â again, just because it looks a little bit cleaner1 (And I might get a new development machine at some pointâ¦)
So the config file for my local development machine right now only says
from config.development import *
Â
Iâve been tempted to add a base.py for shared settings into the mix, but at some point, I probably should go back to developing as opposed to housekeeping.