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 %}
运行示例 »
更小的注释
您还可以使用 {# ... #}
标签来注释掉代码,这对于较小的注释更容易
在 Views 中添加注释
Views 用 Python 编写,Python 注释用 #
字符编写
示例
注释掉 View 中的一段
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 注释教程 中关于 Python 注释的更多内容。