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.1.tar.gz (63.2 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.1-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_template_lsp-1.3.1.tar.gz
  • Upload date:
  • Size: 63.2 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.1.tar.gz
Algorithm Hash digest
SHA256 0261ede9748801edaa686e5085506c0023f358806aca79c828bdfce621c79914
MD5 c9cd0068d1bef933bdf33733adda5811
BLAKE2b-256 54d3fbaf6121080092750aefdd0e41367f830d7fcf75b0aa79fe558dc1181e2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_template_lsp-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a678a7cbe13922f9384ece33e89673334c084fd18084871116e4d86cb953dfd
MD5 e3b6651722705ccbb6de17a89c019221
BLAKE2b-256 3b683db3286540016964ca8ec2ed02e16292f18d43513c58125b027d16846521

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 files

1.3.0

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