• django-模板中的for标签


    django-for标签

    for 标签内容

    views.py

    ###test_for
    
    def  test_if_for(request):
        dic={}
        dic['x']=20
        dic['lst']=['zs','ls','ww']
    
        return render(request,'test_if_for.html',dic)
    

    test_if_for.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>test_if_for</title>
    </head>
    <body>
        {% for name  in lst %}
    
            {% if forloop.first %} 第一个元素--- {%  endif %}
            <p>  {{forloop.counter}} {{name}}</p>
            {% if forloop.last %} 最后一个元素--- {%  endif %}
        {% empty %}
            当前无数据
    
        {% endfor %}
    </body>
    </html>
    

    页面html

    <html lang="en"><head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>test_if_for</title>
    </head>
    <body><text>
        
    
             第一个元素--- 
            </text><p>  1 zs</p>
            
        
    
            
            <p>  2 ls</p>
            
        
    
            
            <p>  3 ww</p>
             最后一个元素--- 
        
    
    </body></html>
    
  • 相关阅读:
    ajax代码及简单封装
    web开发中不同设备浏览器的区分
    JS实现带复选框的下拉菜单
    常用浏览器的编码设置
    PHP实现实现数字补零格式化
    Linux杂碎2/SHELL
    OS
    Linux sudoers
    代理缓存服务器squid
    es6
  • 原文地址:https://www.cnblogs.com/yescarf/p/15089648.html
Copyright © 2020-2023  润新知