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" },
})

Metadata

Release files for django-template-lsp 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-template-lsp 1.3.1
File Size Uploaded Provenance Actions
django_template_lsp-1.3.1.tar.gz 63.2 kB Without provenance Details for django_template_lsp-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-template-lsp 1.3.1
File Interpreter ABI Platform Actions
django_template_lsp-1.3.1-py3-none-any.whl Python 3 none any Details for django_template_lsp-1.3.1-py3-none-any.whl

Total release size: 111.4 kB

Release files / django_template_lsp-1.3.1.tar.gz

Download URL django_template_lsp-1.3.1.tar.gz
Size 63.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0261ede9748801edaa686e5085506c0023f358806aca79c828bdfce621c79914
BLAKE2b-256 checksum
How to use checksums
54d3fbaf6121080092750aefdd0e41367f830d7fcf75b0aa79fe558dc1181e2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / django_template_lsp-1.3.1-py3-none-any.whl

Download URL django_template_lsp-1.3.1-py3-none-any.whl
Size 48.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a678a7cbe13922f9384ece33e89673334c084fd18084871116e4d86cb953dfd
BLAKE2b-256 checksum
How to use checksums
3b683db3286540016964ca8ec2ed02e16292f18d43513c58125b027d16846521
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for django-template-lsp 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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