首页 > 编程语言 > 详细

python django 标签

时间:2020-05-01 18:26:50      阅读:56      评论:0      收藏:0      [点我收藏+]

if

{% if d.age > 20 %}
    {% if d.age < 50 %}
        <h1>{{ d.name }}的年龄大于20小于50</h1>
    {% else %}
        <h1>hello{{ d.name }}</h1>
    {% endif %}
{% elif d.age > 10 %}
    <h1>{{ d.name }}的年龄大于10小于20</h1>
{% else %}
    <h1>{{ d.name }}的年龄小于10</h1>
{%  endif %}

for

{% for name in l %}
    <h1>  {{ forloop.counter0 }}:{{ name }}</h1>
    <h1>  {{ forloop.revcounter0 }}:{{ name }}</h1>
{% endfor %}

for 里面可以放 empty

{% for name in l  %}
    {% if forloop.first %}
        <li class="first">
    {% else %}
        <li>
    {% endif %}
    {{ name }}
    </li>

{% empty %}
    <h1>没有相关文章</h1>
{% endfor  %}

autoescape

 # 传递的上下文信息
 context = {
     "info":"<a href=‘www.baidu.com‘>百度</a>"
 }

 # 模板中关闭自动转义
 {% autoescape off %}
     {{ info }}
 {% endautoescape %}

如果把off改成on,那么就会显示成一个普通的字符串。示例代码如下:

 {% autoescape on %}
     {{ info }}
 {% endautoescape %}

 

python django 标签

原文:https://www.cnblogs.com/hb15988111121/p/12813881.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!