简体   繁体   English

VS Code 中识别为 Django 模板的 HTML 文件

[英]HTML files recognized as Django Template in VS Code

I'm new to VS Code, coming from ST3 and TextMate before that.我是 VS Code 的新手,之前来自 ST3 和 TextMate。 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?有点困惑,为什么在点击右下角的语言指示器后,HTML 没有被自动检测到,也没有作为语言选择提供?

选择“为‘.html’配置文件关联...”后的屏幕截图

I've tried explicitly adding "files.associations": {"*.html": "html"} to the User Settings to no effect.我已经尝试将"files.associations": {"*.html": "html"}显式添加到用户设置,但没有效果。

Running VSCode v1.15.1 on macOS v10.12.6.在 macOS v10.12.6 上运行 VSCode v1.15.1。

Include the following line of setting emmet.includeLanguages": {"django-html": "html"} in VSCode's settings.json:在 VSCode 的 settings.json 中包含以下设置emmet.includeLanguages": {"django-html": "html"}行:

{
"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它在 1.33.1 版上为我修复了

Solved!解决了! I began eliminating extensions and found that Django Template 1.2.0 ( bibhasdn.django-html ) is to blame.我开始消除扩展,发现 Django Template 1.2.0 ( bibhasdn.django-html ) 是罪魁祸首。 As soon as I disabled it, the HTML option returned to the Language Associations menu.一旦我禁用它,HTML 选项就会返回到语言关联菜单。 Hat tip to @ifconfig for confirming I should expect it to be present.给@ifconfig 的帽子提示以确认我应该期望它存在。

相同的图像

1) Click on "select language mode" from bottom right toolbar. 1) 点击右下方工具栏中的“选择语言模式”。

2) Select "Configure file association for .html" from the dropdown. 2) 从下拉菜单中选择“为 .html 配置文件关联”。

3) Select html from the dropdown. 3) 从下拉列表中选择 html。

This will remove html file being marked as Django-html every time you create a html document.每次创建 html 文档时,这都会删除标记为 Django-html 的 html 文件。

These settings worked for me in vscode settings.json这些设置在 vscode settings.json 中对我有用

"files.associations": {
    "**/templates/*.html": "django-html",
    "**/templates/*": "django-txt",
    "**/requirements{/**,*}.{txt,in}": "pip-requirements",
    "*.html": "html"
  },
  "emmet.includeLanguages": { "django-html": "html" }

Python Extension Pack that included DJANGO packages made VSCOde see all html as Django Template and set comments as {%comment%} instead of <!-- -->包含 DJANGO 包的 Python 扩展包使 VSCOde 将所有 html 视为 Django 模板并将注释设置为 {%comment%} 而不是<!-- -->

Removing it solved the issue.删除它解决了问题。

I think the easiest way is to check this.我认为最简单的方法是检查这个。 At the right bottom corner of vs code, you can see a footer as below image.在 vs 代码的右下角,您可以看到如下图所示的页脚。

VS Code IDE 相关部分图片

So, click the Django HTML there.因此,单击那里的Django HTML Then a popup with input can be noticed.然后可以注意到一个带有输入的弹出窗口。 Enter HTML as the input and select HTML .输入HTML作为输入并选择HTML Problem solved.问题解决了。

Just Add this to your Settings.json:只需将此添加到您的 Settings.json 中:

"files.associations": {
    "**/templates/*.html": "django-html",
    "**/templates/*": "django-txt",
    "**/requirements{/**,*}.{txt,in}": "pip-requirements",
    "*.html": "html"
  },
  "emmet.includeLanguages": { "django-html": "html" }

Open the Languages(identifier) menu ( press right Ctl + K then release them and press `M) and there should be HTML.打开语言(标识符)菜单( press right Ctl + K然后释放它们并按`M),应该有 HTML。

语言(标识符)

Finally choose HTML and restart VSCode.最后选择HTML并重新启动 VSCode。

To map an extension to a language in the settings search for association in the results there should be Files:Associations :要将扩展名映射到settings搜索结果中的association中的语言,应该有Files:Associations

在此处输入图片说明

where you can add new key/value pairs.您可以在其中添加新的key/value对。 where key is the extension (Filename Expansion) and value is the language identifier .其中key是扩展名(文件名扩展), value语言标识符

Generally.html and.txt files are recognized as Django Template files by Text-editors.通常 .html 和 .txt 文件被文本编辑器识别为 Django 模板文件。 This can be solved by just adding the given code in VSCode's Setting.json file:这可以通过在 VSCode 的 Setting.json 文件中添加给定代码来解决:

"files.associations": {
        "**/templates/*.html": "django-html",
        "**/templates/*": "django-txt",
        "**/requirements{/**,*}.{txt,in}": "pip-requirements",
        "*.html": "html"
      },

Go to settings.json, and after转到 settings.json,然后

"files.associations": {
    "**/templates/*.html": "django-html",
    "**/templates/*": "django-txt",
    "**/requirements{/**,*}.{txt,in}": "pip-requirements",
    "*.html": "html"
},

put this把这个

"emmet.includeLanguages": {
    "django-html": "html"
},

like this:像这样:

{
"workbench.colorTheme": "Default Dark+",
"editor.fontSize": 15,
"window.zoomLevel": -1,
"files.autoSave": "afterDelay",
"files.associations": {
    "**/templates/*.html": "django-html",
    "**/templates/*": "django-txt",
    "**/requirements{/**,*}.{txt,in}": "pip-requirements",
    "*.html": "html"
},
"emmet.includeLanguages": {
    "django-html": "html"
},
"[django-html]": {



    "editor.quickSuggestions": {
        "other": true,
        "comments": true,
        "strings": true
    }
}

} }

Open your VSCode JSON settings and add these lines打开你的 VSCode JSON 设置并添加这些行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM