zoukankan      html  css  js  c++  java
  • djiango控制语句

    {#    从0开始的索引#}
    {% for foo in value %}
        {#    从0开始的索引#}
        <p>{{ forloop.counter0 }}: {{ foo }}</p>
        {#    是否第一次循环#}
        <p>{{ forloop.first }}</p>
        {#    是否最后一次循环#}
        <p>{{ forloop.last }}</p>
        {#如果列表为空,则走以下内容#}
        {% empty %}
        <p>There are no athletes. Only computer programmers.</p>
    
    {#    <p>{{ forloop.parentloop }}</p>#}
    
    {% endfor %}
    
    {#    从1开始的索引#}
    {% for foo in value %}
         <p>{{ forloop.counter }}: {{ foo }}</p>
    
    {% endfor %}
    
    {#    索引倒叙#}
    {% for foo in value %}
         <p>{{ forloop.revcounter0 }}: {{ foo }}</p>
    
    {% endfor %}
    for循环

    ------{%csrf_token%}:csrf_token标签

         for表单中, 用于生成csrf_token的标签,用于防治跨站攻击验证。注意如果你在view的index里用的是render_to_response方法,不会生效

         其实,这里是会生成一个input标签,和其他表单标签一起提交给后台的。

    ------{% url "别名"%}:路由配置

    re_path(r'pay/login/', views.login, name="James")
    <form action={% url "James" %} method="post">
    <input type="text" name="userName">
    <input type="password" name="password">
    <input type="submit" name="submit">

    ------{% with %}:用更简单的变量名替代复杂的变量名
    {% with total=fhjsaldfhjsdfhlasdfhljsdal %} {{ total }} {% endwith %}

    ------{% verbatim %}: 禁止render  

      {% verbatim %}
      {{ hello }}
      {% endverbatim %}

    ------自定义 filter 和simple_tag
    
    
    filter可以用在if等语句后,simple_tag不可以
    -------------------------------.html
    {% load xxx %}   #首行
        
        
        
     # num=12
    {{ num|filter_multi:2 }} #24
    
    {{ num|filter_multi:"[22,333,4444]" }}
    
    
    {% simple_tag_multi 2 5 %}  参数不限,但不能放在if for语句中
    {% simple_tag_multi num 5 %}


     
  • 相关阅读:
    2020牛客暑期多校训练营(第二场)Interval 网络流平面图转化成最短路
    [P4001 [ICPC-Beijing 2006]狼抓兔子]
    [2020牛客暑期多校训练营(第二场)Greater and Greater]
    [2020牛客暑期多校训练营(第二场)All with Pairs]
    2020牛客暑期多校训练营(第二场)[ Boundary]
    数据结构的特性
    centos7 pgsql启动异常问题
    go实现服务授权
    go 使用线程池做请求限流
    go实现爬虫
  • 原文地址:https://www.cnblogs.com/jiefangzhe/p/10562875.html
Copyright © 2011-2022 走看看