For every Django projects we have a settings.py that contains all the settings for a project but some of these must have an absolute path. So moving a Django project to another directory can be a pain. Luckily we have the os module. These module can and will help us make our projects easy to move.
Just add these line in your settings.py
import os APP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + "/"
Now for every settings that needs an absolute path just prepend the path with APP_PATH
#for static root STATIC_ROOT = APP_PATH+static/ #For templates TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Dont forget to use absolute paths, not relative paths. APP_PATH+template, )
Leave a Reply