{"id":2008,"library":"djlint","title":"djLint","description":"djLint is an HTML template linter and formatter that helps ensure consistency and identify common issues across various template languages, including Django, Jinja, Nunjucks, Handlebars, GoLang, and Angular. It is primarily a command-line interface (CLI) tool. As of version 1.36.4, it continues to receive regular updates with a focus on performance improvements and bug fixes.","status":"active","version":"1.36.4","language":"en","source_language":"en","source_url":"https://github.com/djlint/djLint","tags":["html","linter","formatter","django","jinja","nunjucks","handlebars","golang","angular"],"install":[{"cmd":"pip install djlint","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"djLint is built with Python and requires Python 3.9 or higher.","package":"python","optional":false}],"imports":[{"note":"Used for programmatic configuration, typically within custom linter rules.","symbol":"Config","correct":"from djlint.settings import Config"},{"note":"Helper function for custom linter rules to get line numbers from character positions.","symbol":"get_line","correct":"from djlint.lint import get_line"}],"quickstart":{"code":"import subprocess\nimport os\n\n# Create a dummy HTML file for demonstration\nwith open(\"test_template.html\", \"w\") as f:\n    f.write(\"\"\"\n<div    class=\"my-class\" >\n    <h1>  Hello, {{ name }}! </h1>\n</div>\n    \"\"\")\n\nprint(\"--- Original File ---\")\nwith open(\"test_template.html\", \"r\") as f:\n    print(f.read())\n\n# Run djlint to check for linting issues\nprint(\"\\n--- Linting Check ---\")\nlint_result = subprocess.run([\"djlint\", \"test_template.html\", \"--lint\"], capture_output=True, text=True)\nprint(lint_result.stdout)\nif lint_result.stderr:\n    print(lint_result.stderr)\n\n# Run djlint to reformat the file\nprint(\"\\n--- Reformatting File ---\")\nreformat_result = subprocess.run([\"djlint\", \"test_template.html\", \"--reformat\"], capture_output=True, text=True)\nprint(reformat_result.stdout) # Should be empty if reformat is applied directly to file\nif reformat_result.stderr:\n    print(reformat_result.stderr)\n\nprint(\"\\n--- Formatted File ---\")\nwith open(\"test_template.html\", \"r\") as f:\n    print(f.read())\n\n# Clean up the dummy file\nos.remove(\"test_template.html\")\n","lang":"python","description":"This quickstart demonstrates how to use `djlint` from the command line within a Python script. It creates a sample HTML file, then runs `djlint` to lint and reformat it. The primary interaction with `djlint` is via its CLI."},"warnings":[{"fix":"Upgrade Python to 3.9 or higher.","message":"Python 3.8 support was dropped in version 1.35.3. Users on Python 3.8 or older will need to upgrade their Python environment to use newer versions of djLint.","severity":"breaking","affected_versions":">=1.35.3"},{"fix":"Ensure djLint is updated to version 1.12.2 or higher to resolve duplication issues, and 1.1.1 or higher for non-ASCII character handling on Windows.","message":"Reformatting may duplicate file contents or incorrectly handle non-ASCII characters on Windows with specific older versions.","severity":"gotcha","affected_versions":"v1.1.1 to v1.12.1"},{"fix":"Update djLint to version 1.19.2 or higher to ensure configuration files are properly recognized.","message":"Configuration files (e.g., `pyproject.toml`, `.djlintrc`) might be ignored if placed in the project root on some older Python versions.","severity":"gotcha","affected_versions":"<1.19.2"},{"fix":"Avoid embedding excessively long JSON or complex HTML structures directly into attributes if reformatting by djLint is critical for those sections. Consider externalizing such data or using JavaScript for rendering complex structures.","message":"Reformatting does not work reliably with long JSON/HTML content embedded directly into attribute data within templates.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use spaceless template tags (e.g., `{% if condition -%}class2{%- endif %}`) around conditional attributes to control whitespace, as recommended in best practices.","message":"When `format_attribute_template_tags` is enabled (for Jinja/Nunjucks), conditional attributes without spaceless tags (e.g., `{% if condition %}` instead of `{% if condition -%}`) can lead to unwanted whitespace after formatting, potentially breaking rendering or styling.","severity":"gotcha","affected_versions":"All versions with `format_attribute_template_tags` enabled."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}