zoukankan      html  css  js  c++  java
  • Django 模板语言 for循环

    Django 模板语言 for 循环

    ******  for 循环字典 **********

    USER_DICT = {
        'k1':'root1',
        'k2':'root2',
        'k3':'root3',
    }
    
    # 模板语言循环字典key值 后跟“.keys”不加()。
    {%  for row in user_dict.keys %}
        <li>{{ row }}</li>
    {% endfor %}
    
    # 模板语言循环字典value值 后跟“.values”不加()。
    {%  for row in user_dict.values %}
        <li>{{ row }}</li>
    {% endfor %}
    
    # 模板语言循环字典value值与key值 后跟“.items”不加(),已元组输出。
    {%  for row in user_dict.items %}
        <li>{{ row }}</li>
    {% endfor %}
    
    # 模板语言循环字典value值与key值,取两个值。
    {%  for k,v in user_dict.items %}
        <li>{{ k }}-{{ v }}</li>
    {% endfor %}

    ******* 打印出列表内的所有内容:11,22,33 ***

    # 案例 返回index.html文件传入列表
    render(request,'index.html',{'li':[11,22,33]})
    
    # index.html文件下写入for循环
    {% for item in %}
        <h1>{{item}}</h1>
     {% endfor %}

    ******* 索引取某个值:11  ****

    # 案例 返回index.html文件传入列表
    render(request,'index.html',{'li':[11,22,33]})
    
    {% for item in %}
        <h2>{{item.0}}</h2>
     {% endfor %}
    注:不能使用[]只能以
    ".数字"

    ***** 索引取某个值,打印出字典内的:***

    # 案例 返回index.html文件传入列表
    render(request,'index.html',{'li':11)
    
    {% for item in %}
        <h2>{{item.0}}</h2>
    {% endfor %}
    
    注:不能使用[]只能以".数字"

  • 相关阅读:
    tkinter center window
    get content of all input tag
    pyqt get dynamic content from js
    【python爬虫】selenium的三种等待
    【python爬虫】selenium常用方法总结
    【pathon基础】初识python
    【python爬虫】动态html
    【python爬虫】Xpath
    【python爬虫】正则表达式
    【python爬虫】cookie & session
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/10917860.html
Copyright © 2011-2022 走看看