本文整理汇总了Python中pyramid.configuration.Configurator.add_route方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_route方法的具体用法?Python Configurator.add_route怎么用?Python Configurator.add_route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.add_route方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [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_static_view("static", "tutorial:static")
config.add_route("home", "/", view="tutorial.views.my_view", view_renderer="templates/mytemplate.pt")
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
initialize_sql(db_string, asbool(db_echo))
config = Configurator(settings=settings)
config.add_static_view('static', 'tutorial:static')
config.add_route('home', '/', view='tutorial.views.my_view',
view_renderer='templates/mytemplate.pt')
return config.make_wsgi_app()
示例3: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
db_string = settings.get("db_string")
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get("db_echo", "false")
initialize_sql(db_string, asbool(db_echo))
config = Configurator(settings=settings)
config.begin()
config.add_static_view("static", "tutorial:static")
config.add_route("home", "/", view="tutorial.views.view_wiki")
config.add_route(
"view_page", "/:pagename", view="tutorial.views.view_page", view_renderer="tutorial:templates/view.pt"
)
config.add_route(
"add_page", "/add_page/:pagename", view="tutorial.views.add_page", view_renderer="tutorial:templates/view.pt"
)
config.add_route(
"edit_page", "/:pagename/edit_page", view="tutorial.views.edit_page", view_renderer="tutorial:templates/edit.pt"
)
config.end()
return config.make_wsgi_app()
示例4: ViewWikiTests
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
class ViewWikiTests(unittest.TestCase):
def setUp(self):
self.config = Configurator()
self.config.begin()
def tearDown(self):
self.config.end()
def test_it(self):
from tutorial.views import view_wiki
self.config.add_route('view_page', '{pagename}')
request = testing.DummyRequest()
response = view_wiki(request)
self.assertEqual(response.location, 'http://example.com/FrontPage')
示例5: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
initialize_sql(db_string, asbool(db_echo))
config = Configurator(settings=settings)
config.begin()
config.add_static_view('static', 'tutorial:static')
config.add_route('home', '/', view='tutorial.views.view_wiki')
config.add_route('view_page', '/:pagename',
view='tutorial.views.view_page',
view_renderer='tutorial:templates/view.pt')
config.add_route('add_page', '/add_page/:pagename',
view='tutorial.views.add_page',
view_renderer='tutorial:templates/edit.pt')
config.add_route('edit_page', '/:pagename/edit_page',
view='tutorial.views.edit_page',
view_renderer='tutorial:templates/edit.pt')
config.end()
return config.make_wsgi_app()
示例6: app
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def app(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
config = Configurator(settings=settings)
config.begin()
config.add_static_view('static', 'pyramidapp:static')
config.add_route('home', '/',
view='pyramidapp.views.main_view',
view_renderer='pyramidapp:templates/mytemplate.pt')
config.add_route('tab', '/tab/{name}',
view=view_tab)
config.end()
return config.make_wsgi_app()
示例7: register
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def register():
config = Configurator(reg, package=_context.package)
config.add_route(
name,
pattern,
factory=factory,
header=header,
xhr=xhr,
accept=accept,
path_info=path_info,
request_method=request_method,
request_param=request_param,
custom_predicates=custom_predicates,
view=view,
view_context=view_context,
view_permission=view_permission,
view_renderer=view_renderer,
view_attr=view_attr,
use_global_views=use_global_views,
traverse=traverse,
_info=_context.info
)
示例8: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
config = Configurator(settings=settings)
config.add_static_view('static', 'tutorial:static')
config.add_route('home', '/', view='tutorial.views.view_wiki')
config.add_route('view_page', '/{pagename}',
view='tutorial.views.view_page',
view_renderer='tutorial:templates/view.pt')
config.add_route('add_page', '/add_page/{pagename}',
view='tutorial.views.add_page',
view_renderer='tutorial:templates/edit.pt')
config.add_route('edit_page', '/{pagename}/edit_page',
view='tutorial.views.edit_page',
view_renderer='tutorial:templates/edit.pt')
return config.make_wsgi_app()
示例9: registerRoute
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def registerRoute(pattern, name, factory=None):
""" Register a new :term:`route` using a pattern
(e.g. ``:pagename``), a name (e.g. ``home``), and an optional root
factory.
The ``pattern`` argument implies the route pattern. The ``name``
argument implies the route name. The ``factory`` argument implies
a :term:`root factory` associated with the route.
This API is useful for testing code that calls
e.g. :func:`pyramid.url.route_url`.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.add_route`
method in your unit and integration tests.
"""
reg = get_current_registry()
config = Configurator(registry=reg)
return config.add_route(name, pattern, factory=factory)
示例10: hello_world
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
from paste.httpserver import serve
from pyramid.configuration import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello %(name)s!' % request.matchdict)
if __name__ == '__main__':
config = Configurator()
config.add_route('hello', '/hello/{name}')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
serve(app, host='0.0.0.0')
示例11: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
initialize_sql(db_string, asbool(db_echo))
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings,
root_factory='tutorial.models.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.begin()
config.add_static_view('static', 'tutorial:static')
config.add_route('view_wiki', '/', view='tutorial.views.view_wiki')
config.add_route('login', '/login',
view='tutorial.login.login',
view_renderer='tutorial:templates/login.pt')
config.add_route('logout', '/logout',
view='tutorial.login.logout')
config.add_route('view_page', '/:pagename',
view='tutorial.views.view_page',
view_renderer='tutorial:templates/view.pt')
config.add_route('add_page', '/add_page/:pagename',
view='tutorial.views.add_page',
view_renderer='tutorial:templates/edit.pt',
view_permission='edit')
config.add_route('edit_page', '/:pagename/edit_page',
view='tutorial.views.edit_page',
view_renderer='tutorial:templates/edit.pt',
view_permission='edit')
config.add_view('tutorial.login.login',
renderer='tutorial:templates/login.pt',
context='pyramid.exceptions.Forbidden')
config.end()
return config.make_wsgi_app()
示例12: hola_mundo
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
from paste.httpserver import serve
from pyramid.configuration import Configurator
from pyramid.response import Response
def hola_mundo(request):
nombre = request.matchdict.get('nombre', 'mundo')
return Response('Hola {0}!'.format(nombre))
if __name__ == '__main__':
config = Configurator()
config.add_route('index', '/')
config.add_route('hola', '/{nombre}')
config.add_view(hola_mundo, route_name='hola')
config.add_view(hola_mundo, route_name='index')
app = config.make_wsgi_app()
serve(app, host='0.0.0.0')
示例13: main
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings,
root_factory='tutorial.models.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.add_static_view('static', 'tutorial:static')
config.add_route('view_wiki', '/', view='tutorial.views.view_wiki')
config.add_route('login', '/login',
view='tutorial.login.login',
view_renderer='tutorial:templates/login.pt')
config.add_route('logout', '/logout',
view='tutorial.login.logout')
config.add_route('view_page', '/{pagename}',
view='tutorial.views.view_page',
view_renderer='tutorial:templates/view.pt')
config.add_route('add_page', '/add_page/{pagename}',
view='tutorial.views.add_page',
view_renderer='tutorial:templates/edit.pt',
view_permission='edit')
config.add_route('edit_page', '/{pagename}/edit_page',
view='tutorial.views.edit_page',
view_renderer='tutorial:templates/edit.pt',
view_permission='edit')
config.add_view('tutorial.login.login',
renderer='tutorial:templates/login.pt',
context='pyramid.exceptions.Forbidden')
return config.make_wsgi_app()
示例14: home
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_route [as 别名]
'''
Created on Jun 19, 2012
@author: silviu
'''
from blog.entity.post import loadFirst
from pyramid.configuration import Configurator
from pyramid.renderers import render_to_response
from pyramid.response import Response
from pyramid.static import static_view
from pyramid.view import view_config
from wsgiref.simple_server import make_server
@view_config()
def home(request):
p = loadFirst()
return render_to_response('templates/home.pt',
{'project':'blog', 'text': p.text},
request=request)
if __name__ == '__main__':
config = Configurator()
config.add_route('imageiframe', 'imageiframe/{image}')
config.scan('blog')
config.add_static_view('img', 'blog:img');
config.add_static_view('js', 'blog:js');
config.add_static_view('css', 'blog:css');
config.add_static_view('document', 'blog:documents');
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()