Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML files recognized as Django Template in VS Code

I'm new to VS Code, coming from ST3 and TextMate before that. A bit flummoxed why is HTML not autodetected nor is it offered as a choice of language after clicking on the lower-right language indicator?

Screenshot after selecting "Configure File Association for '.html'..."

I've tried explicitly adding "files.associations": {"*.html": "html"} to the User Settings to no effect.

Running VSCode v1.15.1 on macOS v10.12.6.

like image 939
nootrope Avatar asked Sep 04 '17 21:09

nootrope


People also ask

Can you use HTML with Django?

You can use the Django templates in HTML (full or partial), text, XML, JSON, or nearly any other text-based format.

Which option does Django templates accept?

DjangoTemplates engines accept the following OPTIONS : 'autoescape' : a boolean that controls whether HTML autoescaping is enabled. It defaults to True . Only set it to False if you're rendering non-HTML templates!

What is a template in Django?

In Django, a template is an HTML file that contains placeholders for values that the code provides at run time.

Should I use HTML in my Django code?

A much better practice is to keep HTML out of your code entirely by using templates, so that your code is concerned only with data values and not with rendering. In Django, a template is an HTML file that contains placeholders for values that the code provides at run time.

What is Django in Visual Studio Code?

Django Tutorial in Visual Studio Code. Django is a high-level Python framework designed for rapid, secure, and scalable web development. Django includes rich support for URL routing, page templates, and working with data. In this Django tutorial, you create a simple Django app with three pages that use a common base template.

How to add new key/value pairs to a Django template?

where you can add new key/value pairs. where key is the extension (Filename Expansion) and value is the language identifier. Generally .html and .txt files are recognized as Django Template files by Text-editors. This can be solved by just adding the given code in VSCode's Setting.json file:


3 Answers

Include the following line of setting emmet.includeLanguages": {"django-html": "html"} in VSCode's settings.json:

{
  "python.jediEnabled": false,
  "files.autoSave": "afterDelay",
  "editor.suggestSelection": "first",
  "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
  "editor.minimap.enabled": true,
  "workbench.colorTheme": "Monokai",
  "editor.largeFileOptimizations": false,
  "html.format.indentInnerHtml": true,
  "html.format.indentHandlebars": true,
  "emmet.includeLanguages": {
    "django-html": "html"
  },
  "[django-html]": {

  },
  "files.associations": {
    "*.html": "html"
  }
}

It does the fix for me on version 1.33.1

like image 151
Blue Sky Avatar answered Oct 09 '22 02:10

Blue Sky


Solved! I began eliminating extensions and found that Django Template 1.2.0 (bibhasdn.django-html) is to blame. As soon as I disabled it, the HTML option returned to the Language Associations menu. Hat tip to @ifconfig for confirming I should expect it to be present.

like image 28
nootrope Avatar answered Oct 09 '22 02:10

nootrope


image for the same

1) Click on "select language mode" from bottom right toolbar.

2) Select "Configure file association for .html" from the dropdown.

3) Select html from the dropdown.

This will remove html file being marked as Django-html every time you create a html document.

like image 22
Jith Avatar answered Oct 09 '22 02:10

Jith