Ok so I recall there are some commands you could put in the settings.py
file so that basically when you move your django project to another directory it won't get foo-bar'd up.
I know I could just do this by having a string variable everywhere it mentions the home directory but is there a more elegant way of doing this?
The architecture of a project in Django
root/
Inside settings.py:
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
-> gives the path of the file settings.py: root/main/. This is NOT THE ROOT OF THE PROJECT
PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
-> gives the root of the project: root/. This is THE ROOT OF THE PROJECT.
Django 1.8 already includes the project root directory as BASE_DIR
:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
And you can use it in your app by importing settings
:
from django.conf import settings ... ... print(settings.BASE_DIR)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With