📝 Django

settings.py: Django Configuration

P
Author
Pyland
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
90
🌱
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

📝

pytest-django: Testing Django

Охватываемые темы: Installation, @pytest.mark.djangodb, Fixtures, Testing views.

📅 30.06.2026 👁️ 134
📝

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

📅 30.06.2026 👁️ 100
📝

RAG: Chatting with Documents via Vector Search

RAG (Retrieval-Augmented Generation) is a pattern for working with your own documents. Instead of fine-tuning...

📅 30.06.2026 👁️ 94

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!