Search code examples
htmldjangotemplatesaptana3

Why does Aptana run the comment in Django template?


It is a strange behavior or I am missing something deeper.

In my Django template, this code snippet causes error:

{% if scale.pk %}
<!-- <a class='btn btn-success' style = 'float:left;' href="{% url "scale_update" pk=scale.pk %}">Edit Scale</a> -->

<a class='btn btn-danger' style = 'float:right;' href="{% url "scale_delete" pk=scale.pk %}">Delete Scale</a>
{% endif %}

When I load the page, I see this error:

NoReverseMatch at /scales/
Reverse for 'scale_update' with arguments '()' and keyword arguments '{u'pk': 1}' not found.

On the other hand, when I completely delete the commented part, it works as it's supposed to work. There is only one Python instance running.

Am I missing something about html or django? Or is it a bug in Aptana?


Solution

  • Django doesn't care about HTML comments. It will render all tags it finds on a page. For all it knows, you want to have that text rendered as a comment.

    If you don't want something to render at all, you need to use Django comment tags, not HTML ones: either {# ... #} for a single line, or {% comment %}...{% endcomment %} for multiple lines.