当前位置: 首页>>代码示例>>Python>>正文


Python View.render_index方法代码示例

本文整理汇总了Python中view.View.render_index方法的典型用法代码示例。如果您正苦于以下问题:Python View.render_index方法的具体用法?Python View.render_index怎么用?Python View.render_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在view.View的用法示例。


在下文中一共展示了View.render_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _delayedRender

# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render_index [as 别名]
    def _delayedRender(self, request, settings):
        try:
            properties, per_index = self.properties, self.per_index

            if request.path == "/properties/api.json":
                items = []
                for i in xrange(30):
                    item = self.model.get_item(i)
                    items.append({'id': i, "title": "better " + item['title']})

                request.setHeader("content-type", "application/json")
                request.write(json.dumps(items))

            elif request.path.startswith("/properties/index_"):
                m = re.search(r'.*_(\d+)', request.path)
                if not m:
                    raise Exception('expected number')

                page = int(m.group(1))

                # Divide with roundup
                indices = (properties + per_index - 1) / per_index
                if page >= indices:
                    raise Exception('invalid index number')

                np = "index_%05d.html" % (page+1)

                start = per_index * page
                end = min(per_index * (page + 1), properties)

                index = {
                    'page': page,
                    'nextp': None if page >= (indices-1) else np,
                    'items': self.model.get_items(xrange(start, end))
                }

                request.write(View.render_index(index))

            elif request.path.startswith("/properties/property_"):
                m = re.search(r'.*_(\d+)', request.path)
                if not m:
                    raise Exception('expected number')

                pid = int(m.group(1))

                if pid >= properties:
                    raise Exception('invalid property number')

                item = self.model.get_item(pid)

                request.write(View.render_property(item))
            else:
                raise Exception('unknown page')

        except:
            request.write('can\'t find page. sorry')

        request.finish()
开发者ID:scalingexcellence,项目名称:scrapybook-docker-web,代码行数:60,代码来源:web.py

示例2: int

# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render_index [as 别名]
properties = int(sys.argv[1])
per_index = 30

if not os.path.exists('properties'):
    os.mkdir('properties')

for pid in xrange(0, properties):
    item = model.get_item(pid)

    f = open("properties/property_%06d.html" % pid, "w")
    f.write(View.render_property(item))
    f.close()

indices = (properties + per_index - 1) / per_index
for page in xrange(0, indices):

    np = "index_%05d.html" % (page+1)

    start = per_index * page
    end = min(per_index * (page + 1), properties)

    index = {
        'page': page,
        'nextp': None if page >= (indices-1) else np,
        'items': model.get_items(xrange(start, end))
    }

    f = open("properties/index_%05d.html" % page, "w")
    f.write(View.render_index(index))
    f.close()
开发者ID:scalingexcellence,项目名称:scrapybook-docker-web,代码行数:32,代码来源:create.py


注:本文中的view.View.render_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。