views:

611

answers:

5

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)?

A: 

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.

nbolton
I wasn't really concerned with the html validation but having a little red squiggly line show up on every template was getting annoying. Thanks for your input - luckily T. Stone knew the way to disable the syntax checking globally.
Lance McNearney
Aha, I'm glad I bumped into this thread; its been bugging me for a while now.
nbolton
+6  A: 

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. 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.

T. Stone
Thanks for your help. And I appreciate the tip for saving templates as .django.html to get the extra syntax highlighting!
Lance McNearney
`get_linter` doesn't appear to be present in 5.2 on ubuntu
Mark
+2  A: 

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.

Daniel Swarbrick
+2  A: 

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.

Joor Loohuis
also on Windows
Dercsár
A: 

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.

MB_
Very true, if you're using generic views then you will want to stick with the pre-defined template names.
Lance McNearney