本文整理汇总了Python中view.View.render_property方法的典型用法代码示例。如果您正苦于以下问题:Python View.render_property方法的具体用法?Python View.render_property怎么用?Python View.render_property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.render_property方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _delayedRender
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render_property [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()
示例2: Model
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render_property [as 别名]
from model import Model
from view import View
model = Model()
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))
}