在Python的Django框架中为代码添加注释的方法

WBOY
Release: 2016-06-06 10:05:30
Original
2153 people have browsed it

就像HTML或者Python,Django模板语言同样提供代码注释。 注释使用 {# #} :

{# This is a comment #}

Copy after login

注释的内容不会在模板渲染时输出。

用这种语法的注释不能跨越多行。 这个限制是为了提高模板解析的性能。 在下面这个模板中,输出结果和模板本身是 完全一样的(也就是说,注释标签并没有被解析为注释):

This is a {# this is not
a comment #}
test.

Copy after login

如果要实现多行注释,可以使用`` {% comment %}`` 模板标签,就像这样:

{% comment %}
This is a
multi-line comment.
{% endcomment %}

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!