Registry / web-framework / prettier-plugin-django

prettier-plugin-django

JSON →
library0.5.18jsnpmunverified

Prettier plugin for formatting Django/Jinja templates and Twig/Melody files. Currently at version 0.5.18 with sporadic releases. It leverages the Melody parser to format .django, .jinja, .html, .twig files, offering Twig-specific options like separate print width, multi-tags, and control over quotes/objects. Unlike general Prettier, it targets template syntax with custom indentation and filter formatting. Supports configuration for non-standard tags and coding standards. Active development, but check GitHub for recent updates.

npm install prettier-plugin-django
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-DJ
P
prettier-plugin-django
web-frameworkjavascriptv0.5.18
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = { plugins: ['prettier-plugin-django'] }
import prettierPluginDjango from 'prettier-plugin-django'
The plugin is not imported directly; it's loaded by prettier via plugins array.
Plugin
npm install prettier-plugin-django
require('prettier-plugin-django')
This is not a Node.js module to import; it's a prettier plugin installed via npm and configured in .prettierrc.
configure
// In .prettierrc: { "tabWidth": 4, "plugins": ["prettier-plugin-django"] }
import { prettierPluginDjango } from 'prettier-plugin-django'
Configuration is done in prettier config files, not via import statements.

Installs the plugin, configures prettier with Django-specific options, and formats a simple template.

// 1. Install npm install --save-dev prettier prettier-plugin-django // 2. Create .prettierrc.json { "tabWidth": 4, "printWidth": 80, "twigPrintWidth": 80, "twigSingleQuote": true, "plugins": ["prettier-plugin-django"] } // 3. Format a Django template file // Run: prettier --write "**/*.django" // Example file: template.django // Before: {% if user.is_authenticated %} <p>Welcome, {{ user.username }}!</p> {% endif %} // After: {% if user.is_authenticated %} <p>Welcome, {{ user.username }}!</p> {% endif %}
Debug
Known issues
gotchaPlugin might not be automatically picked up by editors. Need to specify plugins array in .prettierrc with full path.
fix
Add full path to node_modules/prettier-plugin-django in plugins array.
affects: >=0.1
gotchaOptions like twigPrintWidth, twigMultiTags are specific to this plugin; forgetting to set them may lead to unexpected formatting.
fix
Read plugin options and set desired values in .prettierrc.
affects: >=0.1
deprecatedSome options may be deprecated if using newer prettier versions; check compatibility.
fix
Refer to plugin GitHub for updated option names.
affects: >=0.5
gotchaThe plugin uses Melody parser; for complex Twig extensions, custom tags need to be defined in twigMultiTags.
fix
Add non-standard tags as paired entries in twigMultiTags array.
affects: >=0.1
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-django'
Missing plugin installation or incorrect prettier config.
fix
Run 'npm install --save-dev prettier-plugin-django' and ensure prettier config has plugins: ['prettier-plugin-django'].
Unsupported format: .django file not recognized
Parser not set correctly in prettier options.
fix
Add overrides in .prettierrc: { "overrides": [ { "files": "*.django", "options": { "parser": "melody" } } ] }
Invalid option 'twigPrintWidth'
Old version of plugin that doesn't support this option or typo.
fix
Update plugin to latest version; option name is correct.
Upgrade
Version history
0.5.18latest on npm
Audit
Dependencies
prettierrequiredpeer dependency required for formatting
@melody-toolbelt/plugin-djangorequiredcore parser for Django/Jinja templates
Agent activity
6 hits · last 30 days
node
6
Resources
prettier-plugin-django — npm install prettier-plugin-django · libregistry