Skip to main content

Django Template LSP server

The Django Template LSP server enhances your Django development experience with powerful features for navigating and editing template files. This LSP supports:

Completions

  • Custom Tags and Filters: Autocomplete for your custom template tags and filters.
  • Template: Suggestions for extends and includes statements.
  • Load Tag: Autocomplete for {% load %} tags.
  • Static Files: Path suggestions for {% static %} tags.
  • URLs: Autocomplete for {% url %} tags.

Go to Definitions

  • Template: Jump directly to the templates used in extends and includes.
  • URL Tag: Navigate to the views referenced in {% url %} tags.
  • Tags and Filters: Quickly access the definitions of custom tags and filters.
  • Context Variables: Partial support for jumping to context definitions.

Hover Documentation

  • URLs: Inline documentation for {% url %} tags.
  • Tags and Filters: Detailed descriptions for template tags and filters.

Support (tested)

  • Python: 3.10, 3.11, 3.12, 3.13, 3.14
  • Django: 4.2, 5.0, 5.1, 5.2, 6.0

Installation

To install the package globally and isolate it from other Python environments, use pipx:

pipx install django-template-lsp

Once installed, the Django template LSP server is accessible via the following commands:

  • djlsp
  • django-template-lsp

Options

  • env_directories (list[string]) default (list of relative or absolute paths): ["env", ".env", "venv", ".venv"]
  • docker_compose_file (string) default: "docker-compose.yml"
  • docker_compose_service (string) default: "django"
  • django_settings_module (string) default (auto detected when empty): ""
  • cache (boolean/string) default (either true/false or a filepath to the cachefile): false

Data Collection Method

The Django Template LSP Server collects project data by executing a script in the following order:

  1. Virtual Environment:

    • Checks for a virtual environment in the root directory within one of these folders: env, .env, venv, or .venv.
    • If found, runs the django-collector.py script using the virtual environment's Python interpreter.
  2. Docker Compose:

    • If a Docker Compose file (docker-compose.yml by default) is present and includes the specified service (django by default), the script is executed within that Docker service.
  3. Global Python:

    • If neither a virtual environment nor Docker Compose is detected, the script runs using the global python3 installation on the system.

Note: The data collection process will fail if there are Python syntax errors or missing imports in your project.

Type hints

Due to the highly dynamic nature of Python and Django, it can be challenging to identify the available context data within templates. To address this, basic type hint support is provided directly in the template files:

{# type blog: blogs.models.Blog #}

Editors

Helix

In your global or project languages.toml add the following

[[language]]
name = "htmldjango"
file-types = ["html"]

Project settings .helix/languages.toml:

[language-server.djlsp.config]
django_settings_module="<your.settings.module>"

Neovim

In your lspconfig add the following

require'lspconfig'.djlsp.setup{
    cmd = { "<path-to-djlsp>" },
    init_options = {
        django_settings_module = "<your.settings.module>",
        docker_compose_file = "docker-compose.yml",
        docker_compose_service = "django"
    }
}

VSCode

To use the Django template LSP with VSCode read the following readme

Development

Install development dependencies:

make develop

For local development, using Helix is the easiest approach. The configuration for using the source Django template language server, with logging enabled, is already set up.

To start the Helix editor with the environment activated and the correct workspace loaded, run:

make helix

neovim

Locally install the package

make develop

Point neovim's djlsp to the locally installed copy

require("lspconfig").djlsp.setup({
        cmd = { "/path/to/django-template-lsp/.venv/bin/djlsp" },
        root_dir = require("lspconfig.util").root_pattern("manage.py", ".git"),
})

If you want to access the log while developing, add the --enable-log flag to the cmd. The logfile will be written to a file in your current working directory named djlsp.log.

require("lspconfig").djlsp.setup({
        cmd = { "/path/to/django-template-lsp/.venv/bin/djlsp", "--enable-log" },
})

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_template_lsp-1.3.0.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_template_lsp-1.3.0-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file django_template_lsp-1.3.0.tar.gz.

File metadata

  • Download URL: django_template_lsp-1.3.0.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_template_lsp-1.3.0.tar.gz
Algorithm Hash digest
SHA256 0c7a04568f2feb10f3539b87754e1e9ce99d3c635594ece4e7688b827639f33c
MD5 267944973cbe977f2259e9f24ab18a46
BLAKE2b-256 c2e5b78f4fc98f86d6fad60f2d428463ac80701cafc5ff322180354650d7e26f

See more details on using hashes here.

File details

Details for the file django_template_lsp-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_template_lsp-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f34ad2a6d2f382fcef2206f2515a0ad8f2c6d950305e4748ea3fef1c52287b6
MD5 8aab71f21235e056c5790c49695d433f
BLAKE2b-256 d287b444281f71fd2a909643d2af24c0a67c640211e10414d299c465d96fbdc4

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.1

2 files

This release

1.3.0 This release

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.10.0

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.0

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page