Skip to content

DRF Configuration

Alexandar83 edited this page Feb 4, 2025 · 20 revisions

This page provides an overview of the Django Rest Framework (DRF) configuration within The Wall API. It covers core settings in config/settings.py and dynamic configurations from env_utils.py.

1. DRF Core Settings

The DRF core settings are defined in config/settings.py under the REST_FRAMEWORK dictionary:

  • Installed Apps:

    • rest_framework: Core DRF package.
    • rest_framework.authtoken: Enables token-based authentication.
    • drf_spectacular: Generates API documentation and schemas.
    • djoser: Provides user authentication endpoints.
  • Versioning:

    • DEFAULT_VERSIONING_CLASS: Uses URLPathVersioning to extract the API version from the URL (e.g., /api/v2/).
    • DEFAULT_VERSION: Sets the active API version to "v2".
    • ALLOWED_VERSIONS: Limits available API versions to ["v2"].

2. Environment-Based Configuration

The following settings adjust dynamically based on the project environment, using env_utils.py:

  • Project Mode:

    • PROJECT_MODE: Determines whether the app runs in dev, prod_v1, or prod_v2 mode.
  • PostgreSQL Configuration:

    • Used as the primary database for the application.
      💡 For details, refer to the PostgreSQL page.
  • Redis Configuration:

    • Used for caching, Celery task management, and session storage.
      💡 For more information, refer to the Redis page.
  • Celery Configuration:

    • Handles asynchronous task execution.
    • Configured dynamically via env_utils.py.
      💡 For full configuration, refer to the Celery page.

3. Session Management and Password Validation

These settings enforce password validation rules and optimize session storage efficiency.

  • Session Engine:

    • SESSION_ENGINE is set to use Django’s cache-based session storage via django.contrib.sessions.backends.cache.
    • This allows session data to be stored in Redis, improving performance by avoiding database writes for session-related data.
  • Password Validation:

    • Defined in AUTH_PASSWORD_VALIDATORS, including:
      • UserAttributeSimilarityValidator
      • MinimumLengthValidator
      • CommonPasswordValidator
      • NumericPasswordValidator

4. API Schema and Documentation

API documentation is generated with DRF Spectacular, supporting OpenAPI schema generation.

  • The schema is exposed using DEFAULT_SCHEMA_CLASS = drf_spectacular.openapi.AutoSchema.
  • OpenAPI versioning is configured under SPECTACULAR_SETTINGS.

💡 For details, refer to the DRF Spectacular page.

5. Logging

Logging is configured to capture application errors, Celery tasks, caching issues, and API interactions. It includes:

  • File-based logging for different components such as caching, Celery, and wall configuration.
  • Console logging for immediate debugging feedback.
  • Test suite logging to track testing outcomes.

💡 For full details, refer to the Logging Details page.

6. Environment Variables

The application relies on environment variables for configuring database connections, Redis, Celery, logging, and general application behavior. These settings are managed in .env files and dynamically loaded by env_utils.py.

💡 For a detailed breakdown, see the Environment Variables Index page.


Quick Links


Next: System Architecture →

Return to Top
DRF Index
DTS Index
Home Page


Clone this wiki locally