426๐
As answer by Miles, {% comment %}...{% endcomment %}
is used for multi-line comments, but you can also comment out text on the same line like this:
{# some text #}
169๐
Comment tags are documented at https://docs.djangoproject.com/en/stable/ref/templates/builtins/#std:templatetag-comment
{% comment %} this is a comment {% endcomment %}
Single line comments are documented at https://docs.djangoproject.com/en/stable/topics/templates/#comments
{# this won't be rendered #}
- [Django]-Are sessions needed for python-social-auth
- [Django]-What does error mean? : "Forbidden (Referer checking failed โ no Referer.):"
- [Django]-What is more efficient .objects.filter().exists() or get() wrapped on a try
32๐
Using the {# #}
notation, like so:
{# Everything you see here is a comment. It won't show up in the HTML output. #}
- [Django]-How to force Django models to be released from memory
- [Django]-Whats the difference between using {{STATIC_URL}} and {% static %}
- [Django]-Django: manage.py does not print stack trace for errors
9๐
This way can be helpful if you want to comment some Django Template format Code.
{#% include 'file.html' %#}
(Right Way)
Following code still executes if commented with HTML Comment.
<!-- {% include 'file.html' %} -->
(Wrong Way)
- [Django]-Django model blank=False does not work?
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-Why does Django's render() function need the "request" argument?
5๐
This is single-line comments:
{# <p>This is comment</p> #}
This is multi-line comments:
{% comment "This is an optional note for comments" %}
<p>This is comment</p>
<p>This is comment</p>
<p>This is comment</p>
{% endcomment %}
- [Django]-How to change empty_label for modelForm choice field?
- [Django]-Function decorators with parameters on a class based view in Django
- [Django]-Allowing RabbitMQ-Server Connections
0๐
this doesnโt work if you want to comment before {% extends ... %}
In this case better use
<!--
# comment 1
# comment 2
# comment 3
-->
- [Django]-Django: Get list of model fields?
- [Django]-Substring in a django template?
- [Django]-Checking for empty queryset in Django