Komodo Edit 5.2 Django 模板语法错误 - 信息:;前面提到过

发布于 2024-08-17 05:28:21 字数 830 浏览 4 评论 0原文

我正在使用 Komodo Edit 5.2 编辑 html 和 Django 模板文件。它总是在我的模板的第一个标签的第一个 {% block %} 区域内显示单个语法错误。

例如:

{% extends "base.html" %}
{% load i18n %}

{% block title %}Hello{% endblock %}

{% block content %}
    <p>Hello</p> <-- Syntax error on this single line
    <p>Other lines have no errors</p>
{% endblock %}

{% block footer %}
    <p>No errors here</p>
{% endblock %}

给出的语法错误是:

Info: <head> previously mentioned

我知道该错误与我的 标记无关,因为它发生在基本模板和子模板(以及 IDE)中不够聪明,无法在孩子时处理基本模板等。)我的所有 html 标签都正确关闭,并且所有内容都经过 XHTML 严格验证。

这个论坛帖子提到了类似的问题,但没有提供解决方案(并且可能特定于Smarty)语法高亮)。

关于如何解决此错误(或禁用它显示)有什么想法吗?

I am using Komodo Edit 5.2 for editing html and Django template files. It always shows a single syntax error inside the first {% block %} area on the first tag of my template.

For example:

{% extends "base.html" %}
{% load i18n %}

{% block title %}Hello{% endblock %}

{% block content %}
    <p>Hello</p> <-- Syntax error on this single line
    <p>Other lines have no errors</p>
{% endblock %}

{% block footer %}
    <p>No errors here</p>
{% endblock %}

The syntax error given is:

Info: <head> previously mentioned

I know for a fact that the error has nothing to do with my <head> tag since it occurs in the base template and in child templates (and the IDE isn't smart enough to process the base templates when in a child, etc.) All of my html tags are closed properly and everything validates for XHTML strict.

This forum post mentions a similar problem but offers no solution (and may be specific to Smarty syntax highlighting).

Any ideas on how to resolve this error (or disable it from being shown)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

花辞树 2024-08-24 05:28:21

是的,这个问题可以解决,但这确实是一个相当丑陋的方法。

我应该指出这是跟踪器中的一个错误 #77251 (<强>编辑:这在 Komodo 6.1.0 中已修复)。您可以观察该错误以了解它何时真正得到修复。

至于停止红色波浪线——您可以通过手动编辑 Django 模板 HTML 的 python 语言文件来完成此操作。您要编辑的文件是 koDjango_URL_Language.py,可以在 ..ActiveState Komodo Edit 5\lib\mozilla\extensions\[电子邮件受保护]\组件

将以下重写方法添加到 class KoDjangoLanguage 中:

def get_linter(self):
    return None

请注意,这假设您将 django 模板文件保存为 .django.html(如果您还没有保存,请注意,这样做会提供模板标记语法上色了,挺好看的)。编辑文件后,保存并重新加载 Komodo,问题就会消失。

据我了解,每当您升级 Komodo 版本时,都需要重新编辑此文件。希望我们能早日看到整个问题得到解决,并在每个人最喜欢的 IDE 中更好地支持 Django。

Yes, this can be fixed, but it's really rather ugly a method.

I should point out this is a bug that's in the tracker #77251 (edit: this is fixed in Komodo 6.1.0). You could watch that bug to find when it actually gets fixed.

As for stopping the red squiggly lines -- You can do this by editing the python language file for Django template HTML manually. The file you want to edit is koDjango_URL_Language.py, and can be found in ..ActiveState Komodo Edit 5\lib\mozilla\extensions\[email protected]\components.

Add the following override method to class KoDjangoLanguage:

def get_linter(self):
    return None

Note that this assumes you are saving your django template files as .django.html (which on a side note if you have not, doing so provides template-tag syntax coloring, which is kinda nice). After editing the file, save, and reload Komodo and the problem should go away.

From what I understand this file needs to be re-edited whenever you upgrade versions of Komodo as well. Hopefully we'll see sooner than later this whole issue get fixed and better all around support for Django in everyone's favorite IDE's.

你爱我像她 2024-08-24 05:28:21

如果您主要从事 Django 项目,则可以通过编辑 Preferences > 来更改 Komodo 对 *.html 文件的默认处理方式。文件关联并将 *.html 的关联更改为“Django”(例如,通常用于 *.django.html)。这将使您不必重命名所有模板文件。

为了摆脱波浪状的红线,我使用了自定义的 Tidy 配置文件,可以在 Preferences > 下指定该文件。语言>配置文件选择器中的 HTML。该文件的内容很简单:

show-warnings: n

这有点像黑客,因为它也会抑制合法的 HTML 警告。然而,在 Komodo/Tidy 原生支持 Django 模板标签之前,它对我有用。

If you're predominantly working on Django projects, you can change Komodo's default handling of *.html files by editing Preferences > File Associations and changing the association for *.html to "Django" (eg, as it usually is for *.django.html). This will save you having to rename all your template files.

To get rid of the squiggly red line, I use a custom Tidy config file, which can be specified under Preferences > Languages > HTML in the Configuration File chooser. The contents of this file are simply:

show-warnings: n

It's a bit of a hack, since it will be suppressing legitimate HTML warnings too. Until Komodo/Tidy natively supports the Django template tags however, it works for me.

少女七分熟 2024-08-24 05:28:21

如果您正在寻找一种隐藏波浪线的方法,而不是摆弄 HTML Tidy 配置,请尝试以下操作。在“首选项”>“字体和颜色”中,选择“指示器”选项卡。在指标选择器中,有一个名为“Linter error”的条目。将样式指定为“隐藏”,波浪线将被隐藏。状态行仍将显示 linter 信息。这是在 Linux 上的 Komodo Edit 5.2.4 上进行测试的。

If you're looking for a way of just hiding the squigly lines, rather than fiddling with the HTML Tidy configuration, try the following. In Preferences>Fonts and Colors, select the 'Indicators' tab. In the indicator selector there is an entry named 'Linter error'. Assign the style 'hidden' to it, and the squigly lines will be hidden. The statusline will still display the linter information. This is tested on Komodo Edit 5.2.4 on Linux.

后eg是否自 2024-08-24 05:28:21

与将模板文件重命名为 *.django.html 并使用通用视图一样,您可能会遇到 TemplateDoesNotExist 异常,因为 django 只查找 *_list.html 等就我而言。

编辑:此外,当重命名所有模板时,不要忘记重命名所有模板
适当地 {% extends *.html %}{% extends *.django.html %}

As with renaming your templates files to *.django.html and using generic views you might run into TemplateDoesNotExist exceptions since django only looks for *_list.html and such as far as i'm concerned.

edit: Furthermore when renaming all templates don't forget to rename all
{% extends *.html %} to {% extends *.django.html %} appropriately.

烈酒灼喉 2024-08-24 05:28:21

在编辑 Django 模板时,我总是禁用 HTML 错误检查,因为它们不是完全有效的 HTML,正如您可能已经意识到的那样。我不确定这是否可以为 Komodo Edit 完成,但我知道可以为 Komodo IDE 完成,所以人们可能会认为它们在这方面是相似的。无论如何,这个解决方案恐怕有点烦人;你需要为你编辑的每个文件禁用它(我不知道如何全局执行此操作)...

我现在不在我的工作电脑上,但如果没记错的话,底部有一个图标您可以右键单击窗口框架来编辑属性。那里应该有一个禁用 HTML 语法检查的选项。

如果您找不到该选项,请告诉我,我会尽力填补空白。

I always disable HTML error checking when editing Django templates, as they're not wholly valid HTML as you may well have realised. I'm not sure if this can be done for Komodo Edit, but I know it can be done for Komodo IDE, so one might assume they're similar in this respect. Anyway, so the solution is a little annoying I'm afraid; you'll need to disable it for each file you edit (I don't know how to do this globally)...

I'm not on my work PC right now, but if memory serves me, there's an icon at the bottom of the window frame which you can right click to edit properties. Buried deep in there there should be an option to disable HTML syntax checking.

If you can't find the option then let me know and I'll try to fill in the gaps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文