Posted By

chrisaiv on 07/31/11


Tagged

python django


Versions (?)

Python: Dynamically obtain absolute path of project_folder


 / Published in: Python
 

Hard-coding absolute paths is never ideal so here's a quick way to reference your project folder

  1. ############################
  2. #This can be dynamically obtained
  3. ############################
  4. #TEMPLATE_DIRS +=('/Users/user_name/Desktop/django_project/templates/',)
  5.  
  6. ############################
  7. #With a little abspath magic
  8. ############################
  9. import os.path
  10. PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
  11. TEMPLATE_DIRS += (os.path.join(PROJECT_ROOT, "templates"),)

Report this snippet  

You need to login to post a comment.