1

I have the following code in a base.html file in a Django project's header area.

{% if user.is_authenticated %}
  <a class="nav-item nav-link" href="{% url 'create' %}"><span class="oi oi-plus"></span></a>
  <a class="nav-item nav-link" href="javascript:{document.getElementById('logout').submit()}" onclick="">Logout</a>
  <form id="logout" method="POST" action="{% url 'logout' %}">
   {% csrf_token %}
   <input type="hidden" />
  </form>
  {% else %}
  <a class="nav-item nav-link" href="{% url 'signup' %}">Sign Up</a>
  <a class="nav-item nav-link" href="{% url 'login' %}">Login</a>
  {% endif %}

I try to comment out the Javascript area "{% url 'create' %}" but it is not working (the error appears because the 'create' code chunks don't yet exists):

 <a class="nav-item nav-link" href="/*{% url 'create' %}*/"><span class="oi oi-plus"></span></a>

 <!-- <a class="nav-item nav-link" href="{% url 'create' %}"><span class="oi oi-plus"></span></a> -->

 <!-- <a class="nav-item nav-link" href="/*{% url 'create' %}*/"><span class="oi oi-plus"></span></a> -->

When I delete the whole line the error disappears. What I would be interested is how to keep it as a comment so later on when I implement that area I can uncomment it.

sogu
  • 2,738
  • 5
  • 31
  • 90
  • Does this answer your question? [How to put comments in Django templates](https://stackoverflow.com/questions/719915/how-to-put-comments-in-django-templates) – Wimanicesir Jan 13 '20 at 15:30

1 Answers1

6

You have two solutions.

For a code block use:

{% comment %}...{% endcomment %}

For single line you can use this:

{# some text #}
Wimanicesir
  • 4,606
  • 2
  • 11
  • 30