推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
python30
V2EX  ›  Python

django for aaa in aaa_list 循环 中 轮换输出 <tr bgcolor="#ffffff"> 与 <TR bgcolor="#EEEEEE"> 好像用 forloop.counter 但是试了总是不行。

  •  
  •   python30 · Dec 29, 2018 · 2130 views
    This topic created in 2826 days ago, the information mentioned may be changed or developed.
    django for aaa in aaa_list 循环 中 轮换输出 <tr bgcolor="#ffffff"> 与 <TR bgcolor="#EEEEEE"> 好像用 forloop.counter 可以。但是试了总是不行。不知怎么写这个?

    就是每个每个信息的背景轮换。
    2 replies  •  2018-12-29 23:52:05 +08:00
    ayase252
        1
    ayase252  
       Dec 29, 2018 via iPhone
    打开浏览器开发者工具看一下属性写没写对。还有:
    The bgcolor attribute of <tr> is not supported in HTML5. Use CSS instead.

    CSS syntax: <tr style="background-color:red">
    xpresslink
        2
    xpresslink  
       Dec 29, 2018
    肯定可以,一般没有这么弄的,都是直接用 css 的功能
    {% for aaa in aaa_list %}
    <tr style="background-color:{% cycle 'red' 'green' %}">
    ...
    </tr>
    {% endfor %}
    或者
    {% if forloop.counter |divisibleby:"2" %}


    如果用 bootstrap 直接就可以用现成的样式
    <table class="table table-striped">
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2382 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 04:59 · PVG 12:59 · LAX 21:59 · JFK 00:59
    ♥ Do have faith in what you're doing.