forloop.counter0   # 是每次循环的index

红色的div标签,居然可以这样写。

ex:第一次循环的结果

<div class="item active">
  <a href="{{ banner.jump_link }}">
    <img src="{{ banner.image_url }}" alt="...">
  </a>
</div>

循环ing...


                <!-- 表示的是轮播图 -->
<div class="carousel-inner" role="listbox">
{% for banner in banners %}
{% if forloop.counter0 == 0 %}
<div class="item active">
{% else %}
<div class="item">
{% endif %}
<a href="{{ banner.jump_link }}">
<img src="{{ banner.image_url }}" alt="...">
</a>
</div>
{% endfor %}
</div>

django-template-forloop的更多相关文章

  1. django template

    一.模板基本元素 1.例子程序 1)urls.py中新增部分 from django.conf.urls import patterns, url, include urlpatterns = pat ...

  2. Django.template框架 template context (非常详细)

    前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...

  3. django: template - built-in tags

    本节介绍模板中的内置标签:if for 承上文,修改 views.py 如下: from django.shortcuts import render_to_response class Person ...

  4. Django Template模板

    Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def ind ...

  5. Django Template(模板)

    一.模板组成 组成:HTML代码 + 逻辑控制代码 二.逻辑控制代码的组成 1.变量 语法格式 : {{ name }} # 使用双大括号来引用变量 1.Template和Context对象(不推荐使 ...

  6. django入门7之django template和xadmin常用技巧

    django入门7之django template和xadmin常用技巧 <li {% ' == '/course' %}class="active"{% endif %}& ...

  7. django: template using & debug

    模板的作用方法有如下三种: blog/views.py: from django.template import loader, Context, Template from django.http ...

  8. django: template variable

    模板变量用双大括号显示,如: <title>page title: {{title}}</title> 一 模板中使用变量 继续前面的例子,修改 index.html: < ...

  9. The Django template language 阅读批注

    The Django template language About this document This document explains the language syntax of the D ...

  10. django.template.exceptions.TemplateDoesNotExist: rest_framework/api.html

    django.template.exceptions.TemplateDoesNotExist: rest_framework/api.html setting文件中的 INSTALLED_APPS加 ...

随机推荐

  1. 【c++基础】int转string自动补零

    前言 使用to_string函数可以将不同类型的数据转换为string类,请参考here和here.如果string的位数固定,如何进行自动补零呢?请看本文实例! 代码 确定位数,to_string ...

  2. LG3684 [CERC2016]机棚障碍 Hangar Hurdles

    题意 题目描述 你正在评估一些关于一个巨型飞机仓库的建设计划.飞机仓库的地面可以表示为n行n列的网格图,其中每个格子要么是空的,要么有障碍物.行从上到下依次被编号为1到n,列从左到右依次被编号为1到n ...

  3. hasura-graphql 集成 pipelinedb 1.0.0

    pipelinedb 1.0.0 已经是一个标准的pg 扩展了,同时以前的语法也有变动,但是集成进hasura-graphql 更方便了 使用docker-compose 运行 环境准备 docker ...

  4. hasura graphql 集成pipelinedb测试

    实际上因为pipelinedb 是原生支持pg的,所以应该不存在太大的问题,以下为测试 使用doker-compose 运行 配置 docker-compose 文件 version: '3.6' s ...

  5. Oracle plsql乱码

    方法1.执行  set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK 方法2.执行--regedit--查找--NLS_LANG--设置值 SIMPLIFIED ...

  6. java 多线程之 线程优先级和守护线程

    线程优先级的介绍 java 中的线程优先级的范围是1-10,默认的优先级是5."高优先级线程"会优先于"低优先级线程"执行. java 中有两种线程:用户线程和 ...

  7. 【python】class之类属性

    class Foo(object): x=1.5 foo=Foo() print foo.x#通过实例访问类属性 >>>1.5 print Foo.x #通过类访问类属性 >& ...

  8. 【python】python性能分析--待完善

    http://www.oschina.net/translate/python-performance-analysis http://blog.csdn.net/gzlaiyonghao/artic ...

  9. asp.net 网站 发布时 去掉.cs文件

    VS2013在WIN8下扁平的UI和我今天锈垢的大脑,让找这个设置找了好半天!!!   OK,言归正传.   在要发布的网站上右键,选择"发布网站".   在发布窗口中,会让你选择 ...

  10. web中显示中文名称的图片,可以这样配置filter

    com.cy.filter.UrlFilter: package com.cy.filter; import java.io.IOException; import java.net.URLDecod ...