Skip to content

DRF Configuration

Alexandar83 edited this page Feb 24, 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 provides references to dedicated pages for related configurations.

Table of Contents

  1. DRF Core Settings
  2. Environment-Based Configuration
  3. Session Management and Password Validation
  4. API Schema and Documentation
  5. Logging
  6. Environment Variables

1. DRF Core Settings

The DRF core settings are defined in 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 project's configuration adjusts to the environment and is dynamically set in the_wall_api/utils/env_utils.py.

  • Project Mode:

    • The PROJECT_MODE environment variable sets the runtime environment to dev, demo, prod_v1, or prod_v2.
  • PostgreSQL Configuration:

  • Redis Configuration:

  • Celery Configuration:


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

DRF Spectacular generates API documentation and defines OpenAPI schemas.

  • DEFAULT_SCHEMA_CLASS is set to drf_spectacular.openapi.AutoSchema to enable schema generation.
  • OpenAPI versioning is configured under SPECTACULAR_SETTINGS.

💡 For details, refer to the DRF Spectacular page.


5. Logging

Logging is configured to capture application errors, caching issues, Celery tasks output, 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 Error Logging section of the Error Handling page.


6. Environment Variables

The application relies on environment variables for configuring database connections, Redis, Celery, logging, concurrency, and wall configuration settings.
These settings are managed in various .env files:

Environment Configuration Files

  • Common (config/env/common/)

    • redis.conf → Redis memory and persistence settings.
  • Development (config/env/dev/)

    • postgres_dev.env → PostgreSQL credentials.
    • the_wall_api_dev.env → General application settings.
  • Production (config/env/prod/)

    • postgres_prod.env → PostgreSQL credentials.
    • redis_prod.env → Redis authentication.
    • the_wall_api_prod.env → General application settings.

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

💡 Check the *.example files in the relevant folders of the repository for example configuration values.


Next:   API URL Routing
Back to: Project Folder Structure

Return to Top
DTS Index
Home Page


Clone this wiki locally