Using Dynamic MEDIA_ROOT and TEMPLATE_DIRS #
(instead of hard-coded ones)Bad (Default)#
In settings.py don’t write MEDIA_ROOT and TEMPLATE_DIRS as below (which is the default)
TEMPLATE_DIRS = ( "/home/html/project/templates",) MEDIA_ROOT = "/home/html/project/appmedia/"
This will cause you no end of trouble as you switch platforms, attempt to have multiple instances installed on the same machine, etc.
Good#
Use the following instead -
SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) MEDIA_ROOT = os.path.join(SITE_ROOT, 'appmedia') TEMPLATE_DIRS = ( os.path.join(SITE_ROOT, 'templates'),)
CategoryComputing.Lang.Python.Django