Using Unipath to Keep Things Portable. Django tip to avoid hard-coding full paths. I usually set a global called OUR_ROOT in settings.py using os.path.dirname(__file__) and use os.path.join with it to construct any other paths that I need.
Using Unipath to Keep Things Portable. Django tip to avoid hard-coding full paths. I usually set a global called OUR_ROOT in settings.py using os.path.dirname(__file__) and use os.path.join with it to construct any other paths that I need.
I like that idea even better. Makes things a bit more flexible.
Empty - 22nd December 2007 03:20 - #
I'm using os.path.dirname(__file__) also, using Unipath is adding one more dependency to my projects.
dirname doesn't necessarily give you an absolute path. It's almost always to your benefit to obtain a fully absolute path, which requires using either getcwd or realpath:
os.path.join(os.getcwd(), os.path.dirname(__file__))
os.path.realpath(os.path.dirname(__file__))
@Robert: Is true, thanks for the correction.
Great, the right tip at the right time, I was just wondering how to do that best with several developer instances.
Christian Scholz - 4th January 2008 18:06 - #