The Python Oracle

How to put comments in Django templates?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay

--

Chapters
00:00 How To Put Comments In Django Templates?
00:15 Accepted Answer Score 431
00:35 Answer 2 Score 172
00:55 Answer 3 Score 33
01:08 Answer 4 Score 9
01:30 Answer 5 Score 7
01:45 Thank you

--

Full question
https://stackoverflow.com/questions/7199...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #django #djangotemplates #djangocomments

#avk47



ACCEPTED ANSWER

Score 434


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 #}



ANSWER 2

Score 175


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 #}



ANSWER 3

Score 33


Using the {# #} notation, like so:

{# Everything you see here is a comment. It won't show up in the HTML output. #}



ANSWER 4

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