docs
  • Overview
  • 🐍 PYTHON
    • Type Hints
    • PEP8 Style Guide for Python Code
    • 🏡Pipenv
    • Pathlib
  • 🕸Django
    • 🗄models
      • 🎯Best Practices
      • 🚦Django Signals
    • ⚙️ settings
    • DRF
      • Serializer
      • Authentication
      • Permissions
      • Viewsets
    • Testing
      • Faker and Factory Boy
    • 🧪Test Coverage
    • 💦Python-Decouple
    • Django Tips:
    • 💾Django ORM Queryset
    • Custom Exceptions
    • Celery
    • Resources
  • Deploy
    • 🚀Django Deployment
    • 🔒Setup SSL Certificate
  • 💾Database
    • MongoDB
  • 🛠️DevOps
    • 🖥Scripting
      • A First Script
      • Loops
      • Test
      • Variables
      • External programs
      • Functions
    • Command Line Shortcuts
    • Basic Linux Commands
    • 🎛Microservices
    • 🐳Docker
      • Docker Commands
      • Docker Compose
      • Django project
    • Kubernates
  • 📝Software IDE
    • EditorConfig
    • Linters
    • VsCode
Powered by GitBook
On this page

Was this helpful?

  1. 🕸Django

⚙️ 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'
PreviousDjango SignalsNextDRF

Last updated 4 years ago

Was this helpful?