本文整理汇总了Python中models.Page.url方法的典型用法代码示例。如果您正苦于以下问题:Python Page.url方法的具体用法?Python Page.url怎么用?Python Page.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_example_site
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def _create_example_site(user):
site = Site(
name='Example Site',
owner = user,
users = [user],
admins = [user],
example = True,
)
site.put()
for v in [4, 5]:
name = 'Html%d Example' % v
style = Style(site=site, name=name)
style.put()
rev = StyleRevision(parent=style, rev=0)
rev.put()
rev.update(render_template('examples/blog-html%d.css' % v))
style.published_rev = rev
rev = StyleRevision(parent=style, rev=1)
rev.put()
rev.update(render_template('examples/blog-html%d-preview.css' % v))
style.preview_rev = rev
style.put()
page = Page(site=site, name=name, url=url_for('example%d' % v, page_key=0, _external=True), _styles=[style.key()])
page.put()
page.url = url_for('example%d' % v, page_key=page.key(), _external=True)
page.put()
page.queue_refresh()
示例2: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def post(self, ident=None):
if ident:
source = Page.fetch_by_key(ident)
else:
source = Page()
source.name = self.request.get('name', '')
source.url = self.request.get('url', '')
source.phrases = self.request.get('phrases', '')
key = source.put()
self.response.write(key.urlsafe())
示例3: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def post(self):
if not (session and session.get('uid')):
return jsonify({'error': 'Not logged in'})
page = Page(slug=request.form['slug'])
page.url = request.form['url']
page.author = User.objects(id=ObjectId(session.get('uid')))
page.save()
node = Node.objects(id=ObjectId(request.form['nid']))[0]
nodes.pages.append(page)
node.save(cascade=True)
return jsonify({'success':1})
示例4: receive
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def receive(request):
url = urllib.unquote(request.POST.get('url'))
hash = hashlib.sha1(url).hexdigest()
data = urllib.unquote(str(request.POST.get('page_text')))
user_agent = request.META.get('HTTP_USER_AGENT')
p = Page()
p.url = url
p.user_agent = user_agent
p.page_file.save('%s.txt' % hash, ContentFile(data), save=False)
p.save()
return HttpResponse('thanks!', mimetype = 'text/plain')
示例5: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def post(self):
current_user = users.get_current_user()
if not current_user:
return self.redirect('/')
user = User.get_by_id(current_user.user_id())
if not user:
return self.redirect('/register')
try:
page = Page(parent=user.key)
page.user = user.key
page.url = self.request.get('url')
page.name = self.request.get('name')
page.put()
self.redirect('/')
except db.Error:
self.redirect('/')
示例6: store_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import url [as 别名]
def store_pages(self, route_handlers):
"""Stores information on each handler in the datastore and returns a list
of routes for the Router.
:param routes_handler:
A list of FrameworkHandler subclasses which identify routes and
their meta data.
:returns:
A list of webapp2.Route instance.
"""
memcache.delete('navigation_pages')
routes = []
new_key_set = set()
for route_handler in route_handlers:
# Checks if datastore entry exits and uses if it is.
query = Page.query(Page.url == route_handler.url)
datastore_list = query.fetch(1)
if datastore_list:
datastore_entity = datastore_list[0]
else:
datastore_entity = Page()
datastore_entity.url = route_handler.url
datastore_entity.page_title = route_handler.page_title
datastore_entity.appear_in_navigation = route_handler.appear_in_navigation
#TODO: Not write to the datastore if there are no changes to be made
datastore_entity.put()
new_key_set.add(datastore_entity.key)
# Creates a route for each handler and adds it to the routes list
routes.append(webapp2.Route(route_handler.url, route_handler))
# The following removes old pages from the datastore
old_key_set = set(Page.query().fetch(keys_only=True))
ndb.delete_multi(list(old_key_set - new_key_set))
return routes