Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no document formatter for 'django-html'-files installed

In vscode, shift+alt+f for auto-formatting does work in HTML, but not work for Django template file. How can I use autoformatting function in VS code?

like image 631
sangrim shin Avatar asked Mar 15 '19 05:03

sangrim shin


People also ask

How to format django html in vscode?

First, install the beautify extension. Save the changes and go back to your HTML template – you should now be able to format the HTML code automatically by pressing SHIFT - OPTION - F .

What are Django templates?

A Django template is a text document or a Python string marked-up using the Django template language. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags. A template is rendered with a context.


Video Answer


2 Answers

The following worked for me:

  1. Ensure you have the following in your settings.json (Edit accordingly) :
    "files.associations": {
        "**/*.html": "html",
        "**/templates/*/*.html": "django-html",
        "**/templates/*": "django-html",
        "**/requirements{/**,*}.{txt,in}": "pip-requirements"
    },
    "emmet.includeLanguages": {
        "django-html": "html"
    },
  1. Install the beautify extension, then add:
    "beautify.language": {
        "html": [
            "htm",
            "html",
            "django-html"
        ]
    },
  1. May require restart (or may not)
like image 115
hkimani Avatar answered Nov 09 '22 09:11

hkimani


If you are using prettier and needs the beautify only for django-html,

{
    "prettier.disableLanguages": ["django-html"],
    "beautify.language": {
      "html": [
        "django-html"
      ]
    },
    "[django-html]": {
      "editor.formatOnSave": true,
      "editor.defaultFormatter": "HookyQR.beautify"
    }
}
like image 39
Akshay Chandran Avatar answered Nov 09 '22 10:11

Akshay Chandran