The comment tag in Django templates is used to temporarily disable template code or add notes that should not appear in the rendered output. Any content placed between {% comment %} and {% endcomment %} is ignored by the template engine, making it useful for documentation, testing, and hiding template code.
Example:
{% comment "Optional note" %}
Commented out text with {{ create_date|date:"c" }}
{% endcomment %}
Syntax
{% comment 'comment_name' %}
{% endcomment %}
Features of Comment Tag
- Temporarily disable template code.
- Add notes for developers.
- Hide sections of a template during testing.
- Prevent template variables and tags from being rendered.
Understanding Comments in Django template Tags
Create a view that passes data to the template through a context dictionary.
In geeks/views.py,
# import Http Response from django
from django.shortcuts import render
# create a function
def geeks_view(request):
# create a dictionary
context = {
"data" : "<h1>GeeksForGeeks is the Best</h1>",
}
# return response
return render(request, "geeks.html", context)
Next, create a URL pattern to map this view.
from django.urls import path
# importing views from views..py
from .views import geeks_view
urlpatterns = [
path('', geeks_view),
]
Create a template in templates/geeks.html,
Data uncommented :
{{ data }}
Data commented :
{% comment "Optional note" %}
{{ data }}
{% endcomment %}
Let's check is comments are displayed in the template.

Note: The comment tag removes the enclosed content completely during template rendering. Unlike HTML comments (<!-- -->), commented template code is not included in the final HTML source sent to the browser.
Explanation:
- The view passes the variable data to the template through the context dictionary.
- {{ data }} outside the comment block is rendered normally.
- The second {{ data }} is placed inside the comment block.
- Django ignores everything between {% comment %} and {% endcomment %}.
- As a result, only the uncommented content appears in the rendered output.