Created
September 25, 2010 13:05
-
-
Save tomazk/596809 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The comment on join_path implies it will append your path arguments to the result of site_root_path, but it won't.