本文整理汇总了Python中models.Page.get_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_or_404方法的具体用法?Python Page.get_or_404怎么用?Python Page.get_or_404使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.get_or_404方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: css
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_or_404 [as 别名]
def css(page_key):
preview = ('preview' in request.args) and (request.args.get('preview') != '0')
pretty = ('pretty' in request.args) and (request.args.get('pretty') != '0')
if not preview and not pretty:
count_view('css:all')
if request.referrer:
count_view('css:page:%s:%s' % (urlparse(request.referrer).netloc, page_key))
etag = memcache.get(page_key + '-css-etag')
if etag and request.headers.get('If-None-Match', '') == etag:
return 'Not Modified', 304
css = memcache.get(page_key + '-css')
if not css or not etag:
page = Page.get_or_404(page_key)
css = page.compressed_css(False)
etag = _etag(css)
expires = 24 * 60 * 60
memcache.set(page_key + '-css-etag', etag, time=expires)
memcache.set(page_key + '-css', css, time=expires)
return _send_file(css, 'text/css', etag)
else:
page = Page.get_or_404(page_key)
if pretty:
css = page.uncompressed_css(preview)
else:
css = page.compressed_css(preview)
return _send_file(css, 'text/css')
示例2: templatejs
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_or_404 [as 别名]
def templatejs(file_name, page_key=None):
page = None
if page_key:
page = Page.get_or_404(page_key)
js = render_template('js/%s.js' % (file_name), page=page)
if not settings.debug or '__no_debug__' in request.args:
js = jsmin(js)
return Response(js, content_type='text/javascript')
示例3: _whois
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_or_404 [as 别名]
def _whois():
key = request.args.get('key', None)
email = request.args.get('email', None)
page = None
user_sites = None
if key:
page = Page.get_or_404(key)
if email:
user_sites = Site.gql('WHERE users = :1', User(email))
if key or email:
return render_template('_whois_result.html', key=key, page=page, email=email, user_sites=user_sites)
return render_template('_whois.html')
示例4: fetch_preview
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_or_404 [as 别名]
def fetch_preview():
page = Page.get_or_404(request.form.get('page_key', ''))
if 'localhost' in page.url or '127.0.0.1' in page.url or use_url2png is False:
return 'OK'
url = 'http:' + url2png(page.url)
result = urlfetch.fetch(url, deadline=10)
if result.status_code == 200:
page.preview_img = result.content
page.put()
return 'OK'
else:
msg = 'Error while fetching preview image from %s\nStatus %s\nHeaders\n%s\nFinal Url: "%s"' % (url, result.status_code, result.headers, getattr(result, 'final_url', ''))
logging.warn(msg)
return msg, 500
示例5: example5
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_or_404 [as 别名]
def example5(page_key):
page = Page.get_or_404(page_key)
return render_template('examples/blog-html5.html', page=page)