Skip to content

Instantly share code, notes, and snippets.

@imbaczek
Forked from tomazk/relpath.py
Created September 28, 2010 12:22
Show Gist options
  • Save imbaczek/600877 to your computer and use it in GitHub Desktop.
Save imbaczek/600877 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))
join_path = os.path.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment