本文整理汇总了Python中models.Page.gql方法的典型用法代码示例。如果您正苦于以下问题:Python Page.gql方法的具体用法?Python Page.gql怎么用?Python Page.gql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.gql方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import gql [as 别名]
def post(self, slug=None):
if slug:
page = Page.gql("WHERE slug = :1", slug).get()
else:
page = Page()
page.title = self.request.get('title')
page.slug = self.request.get('slug')
page.content = self.request.get('content')
page.order_in_menu = int(self.request.get('order_in_menu'))
page.put()
self.redirect(page.get_url())
示例2: render_template
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import gql [as 别名]
def render_template(self, content_type, template_file, data=None):
if data is None:
data = {}
data['admin'] = users.is_current_user_admin()
data['settings'] = settings
query = Page.gql("WHERE order_in_menu > 0 "
"ORDER BY order_in_menu")
data['pages'] = [p for p in query]
template_path = os.path.join(os.path.dirname(__file__), "templates")
output = template.render(os.path.join(template_path, template_file), data)
self.render(content_type, output)
示例3: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import gql [as 别名]
def get(self, slug):
# we want a canonical url with the trailing slash
# so if it's missing we need to throw a 301, adding the slash in
# the process
if slug[-1] != "/":
self.redirect("%s/" % slug, True)
return
output = get_cache(slug)
if output is None:
try:
item = Page.gql("WHERE internal_url=:1", slug)[0]
except IndexError:
self.error(404)
output = self.render("404.html", {"title": "Page not found"})
self.response.out.write(output)
return
# get a list of related items based on taggings
# remember to filter out the article we're on
related = []
for tag in item.tags:
related += (Tag.all().filter('name =', tag).filter('title !=', item.title))
# we also need to deduplicate the list as sometimes items
# will share tags
seen = []
deduped = []
for related_item in related:
if not related_item.url in seen:
deduped.append(related_item)
seen.append(related_item.url)
context = {
"item": item,
"related": deduped,
"title": item.title,
}
output = self.render("item.html", context)
memcache.add(slug, output, 3600)
self.response.out.write(output)
示例4: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import gql [as 别名]
def get(self, slug=None):
if slug:
page = Page.gql("WHERE slug = :1", slug).get()
else:
page = None
self.render_html("page_edit", {'page': page})
示例5: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import gql [as 别名]
def get(self, slug):
page = Page.gql("WHERE slug = :1", slug).get()
self.render_html("page_view", {'page': page})