zoukankan      html  css  js  c++  java
  • 模板标签


    def templ_tag(resquest):
    """ 模板引擎标签 """
    list_city = ('长沙', '广州', '深圳')
    list_prods = [
    {"name": "名称1", 'price': 100},
    {"name": "名称2", 'price': 200},
    {"name": "名称3", 'price': 300},
    ]
    list_order = ['订单']
    list_order2 = []

    # 字典
    user_info = {
    'username': '张三',
    'age': 35
    }

    return render(resquest, 'tag.html', {
    'list_city': list_city,
    'list_prods': list_prods,
    'list_order': list_order,
    'list_order2':list_order2,
    'user_info': user_info
    })



    逻辑控制
    and, or
    ==, !=
    >, <
    >=,<=
    in, not in
    is

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>标签使用</title>
    <style type="text/css">
    .row1{
    background: red;
    color:white;
    }
    .row2{
    background: blue;
    color:white;
    }
    </style>
    </head>
    <body>
    {# 注释 #}
    <!-- html注释 -->

    <h5>城市渲染</h5>
    <ul>
    {% for item in list_city %}
    <li> {{ item }} </li>
    {% endfor %}
    </ul>


    <h5>商品渲染 </h5>
    <ul>
    {% for item in list_prods %}
    {% if item.price >= 100 %}
    <li>
    {{ item.name }}: {{ item.price }}
    </li>
    {% endif %}
    {% endfor %}
    </ul>

    <h5>商品渲染 倒序 reversed </h5>
    <ul>
    {% for item in list_prods reversed%}
    {% if item.price >= 100 %}
    <li>
    {{ item.name }}: {{ item.price }}
    </li>
    {% endif %}
    {% endfor %}
    </ul>



    <h5>商品渲染 下标</h5>
    <ul>
    {% for item in list_prods reversed%}
    {% if item.price >= 100 %}
    <li>

    {# 0开头#}
    {{ forloop.counter0 }}:

    {# 1开头#}
    {# {{ forloop.counter }}:#}
    {{ item.name }}=> {{ item.price }}
    </li>
    {% endif %}
    {% endfor %}
    </ul>


    <h5>商品渲染 隔行换色</h5>
    <ul>
    {% for item in list_prods reversed%}
    {% if item.price >= 100 %}
    <li class="{% cycle 'row1' 'row2' %}">
    {{ forloop.counter0 }}:
    {{ item.name }}=> {{ item.price }}
    </li>
    {% endif %}
    {% endfor %}
    </ul>





    <h5>订单渲染</h5>

    {% for item in list_order %}
    <li>{{ item }}</li>
    {% endfor %}


    <h5>订单渲染2</h5>
    {% for item in list_order2 %}
    <li>{{ item }}</li>
    {% empty %}
    <li>暂无订单</li>
    {% endfor %}


    <h5>渲染对象</h5>

    {% for key, value in user_info.items %}
    <p>
    {{ key }}: {{ value }}
    </p>
    {% endfor %}
    {# username: 张三 #}
    {# age: 35 #}


    <h5>url标签的使用</h5>

    <a href="{% url 'print_resp_attr' %}" target="_blank">
    打印响应对象
    </a>

    {#<h5>带参数的url</h5>#}

    {#<a href="{% url 'print_resp_attr' 2020 %}?month = 12" target="_blank">#}
    {# 2019d 文章#}
    {#</a>#}


    {#<h5>带命名空间的url</h5>#}

    {#<a href="{% url 'author:show_class' %}" target="_blank">#}
    {# 带命名空间的url #}
    {#</a>#}


    </body>
    </html>
  • 相关阅读:
    谷歌关闭中国区购物搜索小思考
    java生成本地头文件用javah出错问题
    hadoop源代码分析(4)org.apache.hadoop.util包GenericOptionsParser类【原创】
    Ext.util.MixedCollection 用法
    eval 函数用法
    Rails Devise_demo
    rails rake 指南
    accepts_nested_attributes_for
    将Rails3.0无缝升级到Rails3.1.0.beta1
    spork + autotest 实现rails自动化测试
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/11446059.html
Copyright © 2011-2022 走看看