Guest User

Untitled

a guest
Jun 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. '''
  2. If you allways endup googleing how to code down relative paths inside django's
  3. settings.py file using the os.path module, you should consider bookmarking this
  4. code snippet
  5.  
  6. Usage inside settings.py:
  7. SITE_ROOT = site_root_path(__file__)
  8. .
  9. .
  10. .
  11. MEDIA_ROOT = join_path(SITE_ROOT, "media")
  12. TEMPLATE_DIRS = (
  13. join_path(SITE_ROOT,"templates"),
  14. )
  15.  
  16. '''
  17.  
  18. import os
  19.  
  20. def site_root_path(settings_file_path):
  21. '''
  22. @param settings_file_path: __file__ attribute
  23. @return: /path/to/your/django_project
  24. '''
  25. return os.path.dirname(os.path.realpath(settings_file_path))
  26.  
  27.  
  28. join_path = os.path.join
Add Comment
Please, Sign In to add comment