【问题标题】:Is it possible to set up auto indent for Django/html templates in WebStorm?是否可以在 WebStorm 中为 Django/html 模板设置自动缩进?
【发布时间】:2016-04-18 16:20:41
【问题描述】:

问题:当我自动意图时,它会删除模板中任何标记/python 逻辑的所有缩进。

是否有插件可以为 Django 模板提供自动缩进?如果没有,我如何编辑Auto-indent Lines 命令⌃⌥I 以支持如下所述的格式:

index.html:

{% block title %}
  {# note the indent here with django logic #}
  {% render title_tag with title="Sign up Now" global=global %}
{% endblock %}

{% block description %}
  {# note the indent here with html markup #}
  <meta name="description" content="Sign up today with our product.">
{% endblock %}

{% block body %}
{# note the indent here If statement #}
{% if true %}
  <section class="section">
    <p> here too</p> 
  </section>
  {% if false %}
    <div>
      <p>wowo</p>
    </div>
   {% endif %}
{% endif %}

【问题讨论】:

  • 真的怀疑使用任何捆绑/默认的东西可以在这里完成任何事情。为了或多或少正确地格式化这些东西(例如,在块中保持缩进)IDE 必须理解 Django 标签。 WEB-7814ticket 就是在问这个问题(星/投票/评论以获得任何进展的通知)。现在我可能只建议尝试安装“Twig Support”插件(应该与 WebStorm 一起使用)——它使用非常相似的语法,所以在这里应该有所帮助。否则 -- PyCharm 或带有 Python 插件的 IntelliJ
  • Ayeee 这已经足够好了!谢谢!
  • 这真的很有帮助@LazyOne 如果您想将其作为答案,我会将其标记为正确并投票!

标签: python html django webstorm code-formatting


【解决方案1】:

答案:

为了或多或少正确地格式化这些东西(例如,在块内保持缩进)IDE 必须理解 Django 标签。 WEB-7814 ticket 正在询问这个问题(星/投票/评论以获取有关任何进展的通知)。

现在我可能只建议尝试安装“Twig Support”插件(应该与 WebStorm 一起使用)。 Twig 使用非常相似的语法(受 Django 启发),所以它应该在这里提供帮助。否则 -- PyCharm 或带有 Python 插件的完整 IntelliJ。



Twig 插件:插件安装指南 + 格式化 + 使用

  • 打开:主菜单 > Webstorm > 首选项
  • 搜索“插件”

  • 安装 Twig 支持。
  • 重启 Webstorm。
  • 打开:主菜单 > Webstorm > 首选项。
  • 搜索“树枝”
  • 转到编辑器 > 代码样式 > Twig
  • 将制表符大小和缩进设置为 2。
  • 按申请。
  • 搜索“文件类型”
  • 单击“编辑器 > 文件类型”
  • 转到“已识别文件类型”窗格中的“Twig”。
  • 单击“+”并添加“.html”“.tpl”注意:您可能会收到一条错误消息,指出此文件扩展名已经存在 用在别的地方。覆盖以前的使用。

  • 点击应用。
  • 重启 Webstorm。

【讨论】:

    猜你喜欢
    • 2017-01-25
    • 2019-10-23
    • 2011-09-12
    • 2010-12-09
    • 2020-02-19
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 2012-02-19
    相关资源
    最近更新 更多