SyntaxStudy
Sign Up
Django Django Project and App Structure
Django Beginner 1 min read

Django Project and App Structure

A Django project is the top-level container for an entire web application. It contains global settings, the root URL configuration, and one or more apps. Each app is a self-contained module responsible for a specific feature — for example a "blog" app handles posts and comments while an "accounts" app handles user registration. This modular design makes it easy to reuse apps across multiple projects. The settings.py file is the central configuration point. It defines installed apps, database connections, middleware, template directories, static file paths, and much more. Django uses the INSTALLED_APPS list to discover models, management commands, and signals. When you create a new app you must add it to INSTALLED_APPS so Django recognises it. The manage.py utility is your primary tool for interacting with the project. Common commands include runserver to start the development server, makemigrations and migrate to manage database schema changes, createsuperuser to create an admin account, and shell to open an interactive Python shell with the Django environment pre-loaded.
Example
# mysite/settings.py (key sections)

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Your custom apps
    'blog.apps.BlogConfig',
    'accounts.apps.AccountsConfig',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mysite_db',
        'USER': 'dbuser',
        'PASSWORD': 'secret',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

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

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']