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
rogwan
V2EX  ›  Python

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

  •  
  •   rogwan · 2016-10-27 22:37:14 +08:00 · 1458 次点击
    这是一个创建于 2739 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我把博客的文章分页,每页显示 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 条回复    2016-10-28 09:36:55 +08:00
    Ge4Los
        1
    Ge4Los  
       2016-10-27 23:57:38 +08:00
    你这种场景还是按 10 个来分,广告用模板插入更方便吧
    rogwan
        2
    rogwan  
    OP
       2016-10-28 09:36:55 +08:00
    嗯,在固定位置插广告,就干脆把分页条数切割开来写;

    我想在每 10 篇文章的,随机位置插入广告位,不知道怎么搞比较好。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   862 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:11 · PVG 05:11 · LAX 14:11 · JFK 17:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.