簡體   English   中英

VS Code 中識別為 Django 模板的 HTML 文件

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

我是 VS Code 的新手,之前來自 ST3 和 TextMate。 有點困惑,為什么在點擊右下角的語言指示器后,HTML 沒有被自動檢測到,也沒有作為語言選擇提供?

選擇“為‘.html’配置文件關聯...”后的屏幕截圖

我已經嘗試將"files.associations": {"*.html": "html"}顯式添加到用戶設置,但沒有效果。

在 macOS v10.12.6 上運行 VSCode v1.15.1。

在 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"
}

}

它在 1.33.1 版上為我修復了

解決了! 我開始消除擴展,發現 Django Template 1.2.0 ( bibhasdn.django-html ) 是罪魁禍首。 一旦我禁用它,HTML 選項就會返回到語言關聯菜單。 給@ifconfig 的帽子提示以確認我應該期望它存在。

相同的圖像

1) 點擊右下方工具欄中的“選擇語言模式”。

2) 從下拉菜單中選擇“為 .html 配置文件關聯”。

3) 從下拉列表中選擇 html。

每次創建 html 文檔時,這都會刪除標記為 Django-html 的 html 文件。

這些設置在 vscode settings.json 中對我有用

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

包含 DJANGO 包的 Python 擴展包使 VSCOde 將所有 html 視為 Django 模板並將注釋設置為 {%comment%} 而不是<!-- -->

刪除它解決了問題。

我認為最簡單的方法是檢查這個。 在 vs 代碼的右下角,您可以看到如下圖所示的頁腳。

VS Code IDE 相關部分圖片

因此,單擊那里的Django HTML 然后可以注意到一個帶有輸入的彈出窗口。 輸入HTML作為輸入並選擇HTML 問題解決了。

只需將此添加到您的 Settings.json 中:

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

打開語言(標識符)菜單( press right Ctl + K然后釋放它們並按`M),應該有 HTML。

語言(標識符)

最后選擇HTML並重新啟動 VSCode。

要將擴展名映射到settings搜索結果中的association中的語言,應該有Files:Associations

在此處輸入圖片說明

您可以在其中添加新的key/value對。 其中key是擴展名(文件名擴展), value語言標識符

通常 .html 和 .txt 文件被文本編輯器識別為 Django 模板文件。 這可以通過在 VSCode 的 Setting.json 文件中添加給定代碼來解決:

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

轉到 settings.json,然后

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

把這個

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

像這樣:

{
"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
    }
}

}

打開你的 VSCode JSON 設置並添加這些行

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM