django-language-server/docs/clients/sublime-text.md
Josh Thomas edc44aa6f9
Some checks failed
bench / benchmarks (push) Waiting to run
lint / pre-commit (push) Waiting to run
lint / rust-changes (push) Waiting to run
lint / rustfmt (push) Blocked by required conditions
lint / clippy (push) Blocked by required conditions
lint / cargo-check (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
test / Python , Django () (push) Blocked by required conditions
test / tests (push) Blocked by required conditions
build / binary (map[runner:ubuntu-22.04 target:aarch64]) (push) Failing after 4s
build / binary (map[runner:ubuntu-22.04 target:x86_64]) (push) Failing after 5s
build / linux (map[runner:ubuntu-22.04 target:aarch64]) (push) Failing after 4s
build / linux (map[runner:ubuntu-22.04 target:x86_64]) (push) Failing after 3s
build / musllinux (map[runner:ubuntu-22.04 target:aarch64]) (push) Failing after 3s
build / musllinux (map[runner:ubuntu-22.04 target:x86_64]) (push) Failing after 3s
build / binary (map[runner:macos-13 target:x86_64]) (push) Has been cancelled
build / binary (map[runner:macos-14 target:aarch64]) (push) Has been cancelled
build / binary (map[runner:windows-latest target:x86_64]) (push) Has been cancelled
build / windows (map[runner:windows-latest target:x64]) (push) Has been cancelled
build / macos (map[runner:macos-13 target:x86_64]) (push) Has been cancelled
build / macos (map[runner:macos-14 target:aarch64]) (push) Has been cancelled
build / sdist (push) Has been cancelled
build / attest (push) Has been cancelled
add documentation for setting up Sublime Text (#319)
2025-10-08 18:25:52 -05:00

3.6 KiB

title
Sublime Text

Sublime Text

Requirements

Note

Requires Sublime Text 4 (build 4132 or later). The LSP package does not support Sublime Text 3.

Before configuring Django Language Server, you need:

  1. Package Control
  2. The LSP client package (install via Package Control)
  3. Django template syntax support - install Djaneiro via Package Control to get the text.html.django filetype (other Django syntax packages like Django Syntax also work, but may require adjusting the selector value)

Configuration

To use Django Language Server with Sublime Text, you'll need to configure two things: the LSP client settings to enable and run the server, and your Python environment and Django project settings so the server can introspect your project.

LSP Client Settings

Add the following to your LSP settings (Preferences > Package Settings > LSP > Settings):

{
    "clients": {
        "djls": {
            "enabled": true,
            "command": [
                "/path/to/djls",
                "serve"
            ],
            "selector": "text.html.django",
        },
    },
}

Replace /path/to/djls with the actual path to your djls installation:

  • If installed via uv tool install or pipx: typically ~/.local/bin/djls
  • If installed via cargo install: typically ~/.cargo/bin/djls
  • Run which djls in your terminal to find the exact path

Note

GUI applications on Linux and macOS don't inherit your shell's PATH, so using the full path ensures Sublime Text can find djls. If you encounter issues, see the LSP documentation on PATH configuration.

Python/Django Settings

The language server requires two settings to provide full functionality:

  • django_settings_module (required): Your Django settings module (e.g., "myproject.settings")
  • venv_path (optional): Path to your virtual environment

Without these, the language server can't introspect your Django project and will only provide basic built-in template tag completions. The language server attempts to auto-detect these settings from the DJANGO_SETTINGS_MODULE and VIRTUAL_ENV environment variables, and will also search for standard virtual environment directories (.venv, venv, env, .env) in your project root.

However, Sublime Text launches language servers as subprocesses that don't inherit your terminal's environment, so you must explicitly configure at least django_settings_module, and likely venv_path as well unless your venv uses a standard name.

Configuration Methods

Add a [tool.djls] section to your pyproject.toml:

[tool.djls]
django_settings_module = "myproject.settings"
venv_path = "/path/to/venv"

You can also create a dedicated djls.toml or .djls.toml file in your project root if you prefer to keep tool-specific configuration separate.

Sublime project file

Both settings can also be configured via their corresponding environment variables (DJANGO_SETTINGS_MODULE and VIRTUAL_ENV) in your .sublime-project file:

{
    "folders": [{"path": "."}],
    "settings": {
        "LSP": {
            "djls": {
                "env": {
                    "DJANGO_SETTINGS_MODULE": "myproject.settings",
                    "VIRTUAL_ENV": "/path/to/venv"
                }
            }
        }
    }
}