๐Ÿ“ Django

settings.py: Django Configuration

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
315
๐ŸŒฑ
Level
Beginner

settings.py is the central configuration file for a Django project.

Key Settings

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

# Never commit to Git! Store in .env
SECRET_KEY = 'django-insecure-...'

DEBUG = True   # False in production!

ALLOWED_HOSTS = []  # ['mysite.com', 'www.mysite.com'] in production

INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',       # /admin/ panel
    'django.contrib.auth',        # authentication system
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # your apps:
    'tasks',
]

DATABASES

# SQLite (development)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# PostgreSQL (production)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

TEMPLATES

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],  # global templates
        'APP_DIRS': True,  # templates in tasks/templates/
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Static and Media Files

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']   # source files
STATIC_ROOT = BASE_DIR / 'staticfiles'     # after collectstatic

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

Language and Timezone

LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True    # internationalization
USE_TZ = True      # store time in UTC, convert on display

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

CSRF Protection in Django

CSRF (Cross-Site Request Forgery) is an attack in which an adversary tricks the user's browser...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 294
๐Ÿ“

DRF ViewSets and Routers

ViewSet is a class that combines several related views into one. Router automatically generates URLs.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 282
๐Ÿ“

Django Migrations

A migration is a file describing changes to the database schema. Django tracks the state...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 284
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Django RequestLab: from HTTP to secure production Open course curriculum