Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1Panel dev MaxKB Settings Dispatcher

From Leeroopedia
Knowledge Sources
Domains Configuration, Deployment
Last Updated 2026-10-10 00:00 GMT

Overview

Pattern implementation for runtime Django settings selection via the SERVER_NAME environment variable, provided by MaxKB.

Description

MaxKB's settings module uses a dispatcher pattern: the settings/base/__init__.py module reads the `SERVER_NAME` environment variable and imports either `web.py` (full Django app with 17 INSTALLED_APPS, all middleware, DB, cache, templates, i18n) or `model.py` (minimal app with 4 INSTALLED_APPS for the local embedding server). This is set by main.py based on the service being started. A missing or wrong `SERVER_NAME` silently loads the wrong app set, which is a common deployment pitfall.

Usage

Use this pattern when you need to:

  • Understand which settings module is loaded for each service
  • Debug issues caused by wrong SERVER_NAME
  • Add settings for a new service type

Code Reference

Source Location

  • Repository: MaxKB
  • File: apps/maxkb/settings/base/__init__.py

Signature

# apps/maxkb/settings/base/__init__.py
import os

if os.environ.get('SERVER_NAME', 'web') == 'local_model':
    from .model import *  # Minimal settings for local_model service
else:
    from .web import *    # Full Django settings for web service

# main.py sets SERVER_NAME:
if services.__contains__('web'):
    os.environ.setdefault('SERVER_NAME', 'web')
elif services.__contains__('local_model'):
    os.environ.setdefault('SERVER_NAME', 'local_model')

Import

# Settings are loaded automatically by Django via DJANGO_SETTINGS_MODULE
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "maxkb.settings")

I/O Contract

Inputs

Name Type Required Description
SERVER_NAME env Yes 'web' (default) or 'local_model'

Outputs

Name Type Description
INSTALLED_APPS 17 apps (web) or 4 apps (model)
DATABASES Full DB config (web) or none (model)
CACHES Redis config (web) or local memory (model)

Usage Examples

Understanding Settings Selection

# When main.py starts the web service:
os.environ['SERVER_NAME'] = 'web'
# → settings/base/__init__.py imports web.py
# → Full Django app with DB, cache, REST framework, all apps

# When main.py starts the local_model service:
os.environ['SERVER_NAME'] = 'local_model'
# → settings/base/__init__.py imports model.py
# → Minimal app: contenttypes, messages, staticfiles, rest_framework, local_model

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment