{"id":20350,"library":"prettier-plugin-django","title":"prettier-plugin-django","description":"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.","status":"active","version":"0.5.18","language":"javascript","source_language":"en","source_url":"https://github.com/junstyle/prettier-plugin-django","tags":["javascript"],"install":[{"cmd":"npm install prettier-plugin-django","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-django","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-django","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for formatting","package":"prettier","optional":false},{"reason":"core parser for Django/Jinja templates","package":"@melody-toolbelt/plugin-django","optional":false}],"imports":[{"note":"The plugin is not imported directly; it's loaded by prettier via plugins array.","wrong":"import prettierPluginDjango from 'prettier-plugin-django'","symbol":"default","correct":"module.exports = { plugins: ['prettier-plugin-django'] }"},{"note":"This is not a Node.js module to import; it's a prettier plugin installed via npm and configured in .prettierrc.","wrong":"require('prettier-plugin-django')","symbol":"Plugin","correct":"npm install prettier-plugin-django"},{"note":"Configuration is done in prettier config files, not via import statements.","wrong":"import { prettierPluginDjango } from 'prettier-plugin-django'","symbol":"configure","correct":"// In .prettierrc: { \"tabWidth\": 4, \"plugins\": [\"prettier-plugin-django\"] }"}],"quickstart":{"code":"// 1. Install\nnpm install --save-dev prettier prettier-plugin-django\n\n// 2. Create .prettierrc.json\n{\n  \"tabWidth\": 4,\n  \"printWidth\": 80,\n  \"twigPrintWidth\": 80,\n  \"twigSingleQuote\": true,\n  \"plugins\": [\"prettier-plugin-django\"]\n}\n\n// 3. Format a Django template file\n// Run: prettier --write \"**/*.django\"\n\n// Example file: template.django\n// Before:\n{% if user.is_authenticated %} <p>Welcome, {{ user.username }}!</p> {% endif %}\n\n// After:\n{% if user.is_authenticated %}\n    <p>Welcome, {{ user.username }}!</p>\n{% endif %}","lang":"javascript","description":"Installs the plugin, configures prettier with Django-specific options, and formats a simple template."},"warnings":[{"fix":"Add full path to node_modules/prettier-plugin-django in plugins array.","message":"Plugin might not be automatically picked up by editors. Need to specify plugins array in .prettierrc with full path.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Read plugin options and set desired values in .prettierrc.","message":"Options like twigPrintWidth, twigMultiTags are specific to this plugin; forgetting to set them may lead to unexpected formatting.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Refer to plugin GitHub for updated option names.","message":"Some options may be deprecated if using newer prettier versions; check compatibility.","severity":"deprecated","affected_versions":">=0.5"},{"fix":"Add non-standard tags as paired entries in twigMultiTags array.","message":"The plugin uses Melody parser; for complex Twig extensions, custom tags need to be defined in twigMultiTags.","severity":"gotcha","affected_versions":">=0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install --save-dev prettier-plugin-django' and ensure prettier config has plugins: ['prettier-plugin-django'].","cause":"Missing plugin installation or incorrect prettier config.","error":"Cannot find module 'prettier-plugin-django'"},{"fix":"Add overrides in .prettierrc: { \"overrides\": [ { \"files\": \"*.django\", \"options\": { \"parser\": \"melody\" } } ] }","cause":"Parser not set correctly in prettier options.","error":"Unsupported format: .django file not recognized"},{"fix":"Update plugin to latest version; option name is correct.","cause":"Old version of plugin that doesn't support this option or typo.","error":"Invalid option 'twigPrintWidth'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}