⚙️ settings
Modern Django settings
Use Pathlib in Django Settings File:
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": str(BASE_DIR / "db.sqlite3"),
}
}
STATICFILES_DIRS = [
BASE_DIR / "static",
'/var/www/static/',
]TEMPLATES_DIR = BASE_DIR.joinpath('templates')# MEDIA_URL is URL PATH to server media files
# example: https://abc.com/{media_url}/{file_path}
# here https://abc.com is base url,
# media_url is MEDIA_URL from settings.py
# MEDIA_ROOT is path where all media files will be stored.
# example: BASE_DIR / 'mediafiles'
# Here, BASE_DIR is path to project root
# and, mediafiles will be created in project root and all files will
# be uploaded according to path provided in models.
MEDIA_URL = 'media'
MEDIA_ROOT = BASE_DIR / 'mediafiles'Last updated
Was this helpful?