Skip to content

Instantly share code, notes, and snippets.

@tomazk
Created September 25, 2010 13:05
Show Gist options
  • Save tomazk/596809 to your computer and use it in GitHub Desktop.
Save tomazk/596809 to your computer and use it in GitHub Desktop.
'''
If you allways endup googleing how to code down relative paths inside django's
settings.py file using the os.path module, you should consider bookmarking this
code snippet
Usage inside settings.py:
SITE_ROOT = site_root_path(__file__)
.
.
.
MEDIA_ROOT = join_path(SITE_ROOT, "media")
TEMPLATE_DIRS = (
join_path(SITE_ROOT,"templates"),
)
'''
import os
def site_root_path(settings_file_path):
'''
@param settings_file_path: __file__ attribute
@return: /path/to/your/django_project
'''
return os.path.dirname(os.path.realpath(settings_file_path))
def join_path(*args):
'''@return: arg1/arg2'''
return os.path.join(*args)
@tsaylor
Copy link

tsaylor commented Sep 25, 2010

The comment on join_path implies it will append your path arguments to the result of site_root_path, but it won't.

@tomazk
Copy link
Author

tomazk commented Sep 25, 2010

@tsaylor: Agreed. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment