Settings absolute paths in a Django project
Setting the correct path for MEDIA_ROOT and STATIC_ROOT is not a setting that comes out of the box when you start a new Django project.
To keep the same settings in multiple environments i always use this trick, so I can move the project around and always get the correct paths in my settings file.
At the top of your settings.py file, put the following lines:
import os
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
Now when you need to define paths, just use the os.path.join function, like this:
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
and this:
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
and place the 'static' and the 'media' directories in the same directory where settings.py is saved.
Written by Matteo Rosati
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#