2

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.

1

1 Answer 1

6

You have two solutions.

For a code block use:

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

For single line you can use this:

{# some text #}
Sign up to request clarification or add additional context in comments.

2 Comments

@Laif, haha I was confused why my edit didn't pull through. =") Sorry I pushed the wrong button and wanted to edit my own question.
That's pretty funny, no worries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.