本文整理汇总了Python中pyramid.response.Response.encode_content方法的典型用法代码示例。如果您正苦于以下问题:Python Response.encode_content方法的具体用法?Python Response.encode_content怎么用?Python Response.encode_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.encode_content方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ClientView
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import encode_content [as 别名]
class ClientView(BaseViewCallable):
def __init__(self, request):
super(ClientView, self).__init__(request)
self.get_main()
def get_main(self):
template = 'trumpet:templates/mainview.mako'
settings = self.get_app_settings()
basecolor = settings.get('default.css.basecolor', 'white-smoke')
env = dict(appname='frontdoor', basecolor=basecolor)
content = render(template, env)
self.response = Response(body=content)
self.response.encode_content()
示例2: LoaderView
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import encode_content [as 别名]
class LoaderView(BasicView):
def __init__(self, request):
super(LoaderView, self).__init__(request)
subpath = self.request.subpath
if len(subpath) != 1:
subpath = '/'.join(subpath)
self.response = HTTPNotFound('no such resource')
return
reqname = subpath[0]
if not reqname.endswith('.js'):
self.response = HTTPNotFound('no such resource')
return
if reqname in ['cs.js', 'coffee-script.js']:
asset = 'haberdashery:%s' % os.path.join('stdlib', reqname)
self.response = static_asset_response(request, asset)
return
name = reqname[:-3]
template = Template(LOADER_TEMPLATE)
content = template.render(name=name)
self.response = Response(body=content,
content_type='text/javascript')
self.response.encode_content()
示例3: __init__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import encode_content [as 别名]
def __init__(self, request):
super(WebView, self).__init__(request)
#resources = self.request.root.static_resources
#resources.initialize_webview_layout.need()
#resources.favicon.need()
#resources.fullcalendar.need()
#resources.backbone.need()
#resources.require.need()
#resources.require.main.need()
view_name = request.view_name
print "view_name", view_name
nextdir = request.subpath[0]
subpath = os.path.join(*request.subpath)
print "request.subpath", request.subpath
#import pdb ; pdb.set_trace()
if nextdir == 'apples':
subpath = os.path.join(*request.subpath[1:])
js = self.mgr.get_js_by_name(subpath)
print "SUBPATH", subpath
print "JS", js
template = 'trumpet:templates/webview-main.mako'
env = dict(datamain='loader')
content = render(template, env)
self.response = Response(body=content)
elif nextdir == 'stdlib':
asset = 'haberdashery:%s' % '/'.join(request.subpath)
self.response = static_asset_response(request, asset)
elif len(request.subpath) > 1 and request.subpath[1] == 'stdlib':
asset = 'haberdashery:%s' % '/'.join(request.subpath)
self.response = static_asset_response(request, asset)
elif request.subpath[-1] == 'loader.js':
appname = request.subpath[0]
#js = self.mgr.get_js_by_name(appname)
print "LOADER!!!!!!", appname, request.subpath
print "WE MADE IT THIS FAR"
template = Template(LOADER_TEMPLATE)
#env = dict(loader='stdlib/coffee/config')
loader = os.path.join('../', 'app', appname)
print "loader", loader, request.path
env = dict(loader=loader)
#import pdb ; pdb.set_trace()
content = template.render(**env)
self.response = Response(body=content,
content_type='text/javascript')
elif request.subpath[-1] in ['cs.js', 'coffee-script.js']:
asset = 'haberdashery:/stdlib/%s' % request.subpath[-1]
self.response = static_asset_response(request, asset)
elif nextdir == 'app':
name = os.path.join(*request.subpath[1:])
filetype = 'text/html'
if name.endswith('.js'):
name = name[:-3]
filetype = 'text/javascript'
elif name.endswith('.coffee'):
name = name[:-7]
filetype = 'text/coffeescript'
js = self.mgr.get_js_by_name(name)
response = Response(body=js.content,
content_type=filetype)
response.encode_content()
self.response = response
else:
self.data = dict(datamain=subpath)
subpath = os.path.join(*request.subpath)
print "SSSSSSSSSSSSUBPATH", subpath
template = 'trumpet:templates/webview-main.mako'
env = dict(datamain='%s/loader' % subpath)
content = render(template, env)
self.response = Response(body=content)
self.context = self.request.context