How To Use Relative Paths In Django Settings
I have been using this technique for a while and it seems to be very handy especially in the production environment. You don't have to change the paths in your Django settings.py every time you change the location of your app or simply changing and uploading the settings.py file via FTP from your testing environment to your server.
One of the most useful features of this trick is to set relative paths for the TEMPLATE_DIRS variable but it can also be used for other variables such as STATICFILES_DIRS or any other custom variables you want to define in your settings.py file.
import os.path #this will give the current location of your settings.py file SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) STATICFILES_DIRS = ( os.path.join(SITE_ROOT, 'resources'), ) TEMPLATE_DIRS = ( os.path.join(SITE_ROOT, 'html'), )
1)Django Comments Framework Tutorial
2)How To Update MySQL Database To Reflect The Changes In Django Model
3)Django Development With Eclipse and PyDev
4)How To Change MySQL Password
5)Why Python Doesn't Import All Libraries Like In Java