【问题标题】:Pagination in Jinja2 on Google App EngineGoogle App Engine 上 Jinja2 中的分页
【发布时间】:2012-08-17 10:55:47
【问题描述】:
  1. Google App Engine 上的 Jinja2 有分页功能吗?

  2. 我正在考虑使用来自 django 的 from django.core.paginator import Paginatorhttps://docs.djangoproject.com/en/dev/topics/pagination/?from=olddocs

我想我需要在 app.yaml 中包含 django 库:

libraries:
- name: django
  version: "1.2"

但我想知道这是否会使我的应用程序运行速度变慢,因为我包含更多库。

【问题讨论】:

    标签: python django google-app-engine pagination jinja2


    【解决方案1】:

    对于分页,建议使用query with cursor:

    q = ndb.query()
    cursor = ndb.Cursor(urlsafe=self.request.get('cursor'))
    items, next_curs, more = q.fetch_page(10, start_cursor=cursor) 
    if more:
        next_c = next_curs.urlsafe()
    else:
        next_c = None
    self.generate('home.html', {'items': items, 'cursor': next_c })
    

    并在模板中添加一个“更多”按钮

    {% if cursor %}
        <a class="btn" href="?cursor={{cursor}}">more..</a>
    {% endif %}
    

    'old' db.Model 是否有类似的东西

    【讨论】:

      猜你喜欢
      • 2011-01-22
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多