I’m working on a Django project using two different machine, a Windows and a Mac Os X. I have everything synchronized over Dropbox. The problem is that some settings in settings.py are single strings (e.g. the MEDIA_ROOT or the STATIC_ROOT) and not tuples. That means that I can set a proper path for, let’s say STATIC_ROOT for only one of the two OS. In the other one of course it won’t work.
I was wondering if there exist a way to recognize the OS python is running on and choose the proper setting through a condition according to it.
You shouldn’t be setting absolute paths in the first place. Use something like
os.path.dirname(__file__)to get the directory that settings.py is in, then combine it with the specific path piece, e.g.:Then, it no longer matters what platform you’re running on. FWIW, it’s typical to actually store the base path, since it will be needed so often, e.g.: