parsed.org

Tips by tag: location

Path Calculation by xinu on Mar 30, 2007 01:13 PM

If you need to tell a python framework where your templates, etc. are located, it helps to determine the location of the current module.

BASE_PATH = os.path.abspath(os.path.join(os.path.dirname(__FILE__), '..'))
TEMPLATES = os.path.join(BASE_PATH, 'templates')

Assuming you're running this code in /path/to/module.py, BASE_PATH will be set to /path. Other os.path tricks can be used to dynamically set paths in this way.

locationosparsingpathpython
RSS