Posted By

chrisaiv on 12/24/11


Tagged

django


Versions (?)

Django: Configuring settings.py to rely on relative paths rather than absolute


 / Published in: Django
 

Hate absolute Paths? Me too, I always end up forgetting to change things around when I go into production mode. Thankfully, there's a nice, clean way to have Python do all the hard work.

  1. import os.path
  2. PROJECT_DIR = os.path.dirname(__file__)
  3.  
  4.  
  5. #Here are examples of how you can set your MEDIA_ROOT and TEMPLATE_DIRS
  6. MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
  7.  
  8. TEMPLATE_DIRS = (
  9. os.path.join( PROJECT_DIR, 'templates' ),
  10. )

Report this snippet  

You need to login to post a comment.