Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

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.

Tagged , , , ,

5 comments

  1. I like that idea even better. Makes things a bit more flexible.

    Empty - 22nd December 2007 03:20 - #

  2. I'm using os.path.dirname(__file__) also, using Unipath is adding one more dependency to my projects.

    Nuno Mariz - 22nd December 2007 15:53 - #

  3. 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 Brewer - 24th December 2007 06:11 - #

  4. @Robert: Is true, thanks for the correction.

    Nuno Mariz - 26th December 2007 23:21 - #

  5. 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 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site