推荐学习书目
› 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
rogwan
V2EX  ›  Python

怎么在( sqlalchemy)的分页中,随机位置插入一些内容?

  •  
  •   rogwan · Oct 27, 2016 · 2069 views
    This topic created in 3669 days ago, the information mentioned may be changed or developed.

    我把博客的文章分页,每页显示 10 篇文章,比如:

    Pagination = Article.query.filter(Article.article_id == foo).paginate(page, per_page=10)
    articles = pagination.items

    现在,我想在每页显示的 10 篇文章中,随机插入 3 条广告内容。意思就是:
    在第 1-10 篇文章中间,随机插入 3 个空位,显示广告内容;
    在第 11-20 篇文章中间,随机插入 3 个空位,显示广告内容;
    如此类推 ...

    这个要怎么实现比较好?

    2 replies  •  2016-10-28 09:36:55 +08:00
    Ge4Los
    Ge4Los
    Oct 27, 2016
    1
    你这种场景还是按 10 个来分,广告用模板插入更方便吧
    rogwan
    rogwan
    OP
    Oct 28, 2016
    2
    嗯,在固定位置插广告,就干脆把分页条数切割开来写;

    我想在每 10 篇文章的,随机位置插入广告位,不知道怎么搞比较好。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2149 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:40 · PVG 15:40 · LAX 23:40 · JFK 02:40
    ♥ Do have faith in what you're doing.