V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-12-29 23:03:14 +08:00 · 1347 次点击
    这是一个创建于 1916 天前的主题,其中的信息可能已经有所发展或是发生改变。
    django for aaa in aaa_list 循环 中 轮换输出 <tr bgcolor="#ffffff"> 与 <TR bgcolor="#EEEEEE"> 好像用 forloop.counter 可以。但是试了总是不行。不知怎么写这个?

    就是每个每个信息的背景轮换。
    2 条回复    2018-12-29 23:52:05 +08:00
    ayase252
        1
    ayase252  
       2018-12-29 23:22:59 +08:00 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  
       2018-12-29 23:52:05 +08:00
    肯定可以,一般没有这么弄的,都是直接用 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">
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5423 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:54 · PVG 16:54 · LAX 01:54 · JFK 04:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.