本文整理汇总了Python中pyramid.config.Configurator.add_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_view方法的具体用法?Python Configurator.add_view怎么用?Python Configurator.add_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
from pyramid_mako import add_mako_renderer
del global_config # unused
config = Configurator(settings=settings)
init_tilegeneration(settings['tilegeneration_configfile'])
global tilegeneration
config.include(c2cwsgiutils.pyramid.includeme)
health_check.HealthCheck(config)
add_mako_renderer(config, ".html")
config.add_route(
'admin', '/{}/'.format(tilegeneration.config['server']['admin_path']),
request_method='GET',
)
config.add_route(
'admin_run', '/{}/run'.format(tilegeneration.config['server']['admin_path']),
request_method='POST',
)
config.add_route('tiles', '/*path', request_method='GET')
config.add_view(PyramidView, route_name='tiles')
config.scan('tilecloud_chain.views')
return config.make_wsgi_app()
示例2: app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def app():
config = Configurator()
config.include('pyramid_wiring')
graph = Graph()
graph.register_scope(RequestScope, RequestScope())
class Counter(object):
def __init__(self):
self.count = 1
graph.register_provider('counter', FactoryProvider(Counter, scope=RequestScope))
config.set_object_graph(graph)
def count(request, counter=injected('counter')):
# Increment the counter
count = counter.count
counter.count += 1
# Get the counter from the graph again and make sure it's the same
assert graph.get('counter') is counter
return count
config.add_route('count', '/count')
config.add_view(count, route_name='count', renderer='string')
return TestApp(config.make_wsgi_app())
示例3: setUp
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def setUp(self):
configurator = Configurator()
configurator.add_route("example", "/example", request_method="GET")
configurator.add_route("trace_context", "/trace_context", request_method="GET")
configurator.add_view(
example_application, route_name="example", renderer="json")
configurator.add_view(
local_tracing_within_context, route_name="trace_context", renderer="json")
self.observer = mock.Mock(spec=BaseplateObserver)
self.server_observer = mock.Mock(spec=ServerSpanObserver)
def _register_mock(context, server_span):
server_span.register(self.server_observer)
self.observer.on_server_span_created.side_effect = _register_mock
self.baseplate = Baseplate()
self.baseplate.register(self.observer)
self.baseplate_configurator = BaseplateConfigurator(
self.baseplate,
trust_trace_headers=True,
)
configurator.include(self.baseplate_configurator.includeme)
app = configurator.make_wsgi_app()
self.test_app = webtest.TestApp(app)
示例4: assert_cache_enabled
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def assert_cache_enabled(self, cache_factory):
settings = {
"boto3.sessions": "default",
"boto3.clients": "s3",
"boto3.client.s3.session": "default",
"boto3.client.s3.service_name": "s3",
"boto3.resources": "s3",
"boto3.resource.s3.session": "default",
"boto3.resource.s3.service_name": "s3",
"boto3.cache_factory": cache_factory,
}
config = Configurator(settings=settings)
config.include("pyramid_boto3")
def aview(request):
session = request.find_service(name="boto3.session.default")
self.assertIsNotNone(session)
s3cli = request.find_service(name="boto3.client.s3")
self.assertIsNotNone(s3cli)
s3res = request.find_service(name="boto3.resource.s3")
self.assertIsNotNone(s3res)
return "OK"
config.add_view(aview, route_name="root", renderer="json")
config.add_route("root", pattern="/")
app = config.make_wsgi_app()
request = Request.blank("/")
response = request.get_response(app)
self.assertEqual(response.json_body, "OK")
del app
示例5: create_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def create_app(settings):
from pyramid.config import Configurator
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.path import AssetResolver
from pyramid.response import FileResponse
from h.auth import HybridAuthenticationPolicy
from h.models import groupfinder
authn_policy = HybridAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.add_route('ok', '/ruok')
config.add_view(lambda request: 'imok', renderer='string', route_name='ok')
# Include all the pyramid subcomponents
config.include(includeme)
return config.make_wsgi_app()
示例6: factory
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def factory(cls, global_config, egg, resource_name):
self = DocServer(egg, resource_name)
config = Configurator(settings=global_config)
config.add_route('catchall', '/*subpath')
config.add_view(self.view, route_name='catchall', renderer='json')
app = config.make_wsgi_app()
return app
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
settings = dict(settings)
settings.setdefault('jinja2.i18n.domain', 'hello_world')
# Start Sphinx Include 2
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
config = Configurator(root_factory=get_root, settings=settings,
session_factory=my_session_factory)
# End Sphinx Include 2
config.add_translation_dirs('locale/')
# Start Include
config.include('pyramid_jinja2')
# End Include
config.add_static_view('static', 'static')
config.add_view('hello_world.views.my_view',
context='hello_world.models.MyModel',
renderer="mytemplate.jinja2")
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, "sqlalchemy.")
settings["db.sessionmaker"] = DBSession
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
initialize_sql(engine, [populate, populate_wiki, populate_feeds])
session_factory = session_factory_from_settings(settings)
root_factory = "trumpet.resources.RootGroupFactory"
request_factory = "trumpet.request.AlchemyRequest"
config = Configurator(
settings=settings,
root_factory=root_factory,
request_factory=request_factory,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=session_factory,
)
configure_static(config)
# config.include('pyramid_fanstatic')
configure_base_layout(config)
config.add_static_view("static", "static", cache_max_age=3600)
config.add_route("home", "/")
config.add_view("plum.views.MainViewer", route_name="home", renderer=basetemplate, layout="base")
configure_login(config)
configure_rssviewer(config, "/rssviewer")
configure_wiki(config, "/wiki")
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
models.initialize(engine)
config = Configurator(settings=settings,
root_factory='bonanza.lib:RootFactory',
session_factory=session_factory_from_settings(settings),
# authentication_policy=AuthTktAuthenticationPolicy(
# '5e04c5f06208def3c5becd6db74f8d11733a912a',
# callback=bonanza.security.lookup_userid),
# authorization_policy=ACLAuthorizationPolicy()
)
config.include('pyramid_jinja2')
config.include('pyramid_scss')
config.add_static_view('static', 'bonanza:static', cache_max_age=3600)
# entity
config.add_route('home', '/')
config.add_view(route_name='home', view='bonanza.controllers.home.get_index',
renderer='/home/index.jinja2', request_method='GET')
# scss
config.add_route('css', '/css/{stylesheet}.css')
config.add_view(route_name='css', view='bonanza.controllers.static.get_css',
renderer='scss', request_method='GET')
config.commit()
add_template_filters(config)
return config.make_wsgi_app()
示例10: create_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def create_app():
config = Configurator()
config.add_route('instagram', '/instagram')
config.add_view(process_instagram_oauth, route_name='instagram')
app = config.make_wsgi_app()
return app
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
settings = dict(settings)
settings.setdefault('jinja2.i18n.domain', 'twends-web')
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
config = Configurator(root_factory=get_root, settings=settings, session_factory = my_session_factory)
config.add_translation_dirs('locale/')
config.include('pyramid_jinja2')
config.add_static_view('static', 'static')
config.add_view('twendsweb.views.my_view',
context='twendsweb.models.RootModel',
renderer='mytemplate.jinja2')
config.add_view('twendsweb.views.view',
#name='node_view',
context='twendsweb.models.Node',
renderer='tweets.jinja2')
config.add_subscriber(add_redis,
'pyramid.events.NewRequest')
return config.make_wsgi_app()
示例12: make_wsgi_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def make_wsgi_app():
config = Configurator()
config.add_route('do_scrypt', '/', request_method='POST')
config.add_route('do_healthcheck', '/', request_method='GET')
config.add_view(do_scrypt, route_name='do_scrypt')
config.add_view(do_healthcheck, route_name='do_healthcheck')
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
config = Configurator(settings=settings)
# config.add_subscriber('pyramidchameleoni18n.subscribers.add_renderer_globals',
# 'pyramid.events.BeforeRender')
# config.add_subscriber('pyramidchameleoni18n.subscribers.add_localizer',
# 'pyramid.events.NewRequest')
config.add_translation_dirs('pyramidchameleoni18n:locale')
config.add_static_view('static', 'pyramidchameleoni18n:static', cache_max_age=3600)
config.add_route('home', '/')
config.add_view('pyramidchameleoni18n.views.my_view',
route_name='home',
renderer='templates/mytemplate.pt')
config.add_route('test_i18n', '/test')
config.add_view('pyramidchameleoni18n.views.test_i18n_view',
route_name='test_i18n',
renderer='templates/test_i18n.pt')
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main(global_config, **settings):
""" Return a Pyramid WSGI application. """
settings['config_uri'] = global_config['__file__']
config = Configurator(registry=getGlobalSiteManager())
config.setup_registry(settings=settings)
config.add_translation_dirs('assembl:locale/')
def my_locale_negotiator(request):
locale = default_locale_negotiator(request)
available = settings['available_languages'].split()
locale = locale if locale in available else None
if not locale:
locale = request.accept_language.best_match(
available, settings.get('pyramid.default_locale_name', 'en'))
request._LOCALE_ = locale
return locale
config.set_locale_negotiator(my_locale_negotiator)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('widget', 'widget', cache_max_age=3600)
config.add_view(maintenance_message)
config.add_notfound_view(maintenance_message)
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_view [as 别名]
def main():
config = Configurator()
config.add_route('hello', '/hello/{name}')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()