Django 注释标签


注释

注释允许您包含应该被忽略的代码部分。

示例

<h1>Welcome Everyone</h1>
{% comment %}
  <h1>Welcome ladies and gentlemen</h1>
{% endcomment %}
运行示例 »

注释说明

您可以在注释中添加消息,以帮助您记住编写注释的原因,或作为消息发送给阅读代码的其他人。

示例

在您的注释中添加描述:

<h1>Welcome Everyone</h1>
{% comment "this was the original welcome message" %}
    <h1>Welcome ladies and gentlemen</h1>
{% endcomment %}
运行示例 »

较小的注释

您还可以使用{# ... #}注释掉代码时使用标签,这对于较小的注释来说会更容易:

示例

注释掉Everyone这个词:

<h1>Welcome{# Everyone#}</h1>
运行示例 »

在视图中使用注释

视图是用 Python 编写的,Python 注释是用#特点:

示例

注释掉视图中的一个部分:

from django.http import HttpResponse
from django.template import loader

def testing(request):
  template = loader.get_template('template.html')
  #context = {
  # 'var1': 'John',
  #}
  return HttpResponse(template.render())
运行示例 »

阅读更多关于 Python 的注释 in outPython 注释教程