简体   繁体   English

一起注释 HTML、CSS、Javascript 代码

[英]Commenting out HTML, CSS, Javascript Code Together

I have the following code in a base.html file in a Django project's header area.我在 Django 项目标题区域的base.html文件中有以下代码。

{% 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):我尝试注释掉 Javascript 区域 "{% url 'create' %}" 但它不起作用(出现错误是因为 'create' 代码块尚不存在):

 <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.我感兴趣的是如何将其保留为注释,以便稍后在实现该区域时取消注释。

You have two solutions.你有两个解决方案。

For a code block use:对于代码块使用:

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

For single line you can use this:对于单行,您可以使用:

{# some text #}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM