当前位置: 首页>>代码示例>>Python>>正文


Python Configurator.add_view方法代码示例

本文整理汇总了Python中pyramid.configuration.Configurator.add_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_view方法的具体用法?Python Configurator.add_view怎么用?Python Configurator.add_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.configuration.Configurator的用法示例。


在下文中一共展示了Configurator.add_view方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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()
开发者ID:blaflamme,项目名称:pyramid,代码行数:36,代码来源:__init__.py

示例2: main

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=get_root, settings=settings)
    config.add_view('myproject.views.my_view',
                    context='myproject.models.MyModel',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    return config.make_wsgi_app()
开发者ID:pyeek,项目名称:pyramid,代码行数:11,代码来源:__init__.py

示例3: register

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [as 别名]
 def register():
     config = Configurator(reg, package=_context.package)
     config.add_view(
         permission=permission, context=context, view=view, name=name,
         request_type=request_type, route_name=route_name,
         request_method=request_method, request_param=request_param,
         containment=containment, attr=attr, renderer=renderer,
         wrapper=wrapper, xhr=xhr, accept=accept, header=header,
         path_info=path_info, custom_predicates=custom_predicates,
         _info=_context.info)
开发者ID:markramm,项目名称:pyramid,代码行数:12,代码来源:zcml.py

示例4: main

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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")
    get_root = appmaker(db_string, asbool(db_echo))
    config = Configurator(settings=settings, root_factory=get_root)
    config.add_static_view("static", "meteoglobal:static")
    config.add_view("meteoglobal.views.view_root", context="meteoglobal.models.MyApp", renderer="templates/root.pt")
    config.add_view("meteoglobal.views.view_model", context="meteoglobal.models.MyModel", renderer="templates/model.pt")
    return config.make_wsgi_app()
开发者ID:tamentis,项目名称:meteoglobal,代码行数:15,代码来源:__init__.py

示例5: app

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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(root_factory=get_root, settings=settings)
    config.begin()
    config.add_view('myproject.views.my_view',
                    context='myproject.models.MyModel',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    config.end()
    return config.make_wsgi_app()
开发者ID:junkafarian,项目名称:pyramid,代码行数:16,代码来源:__init__.py

示例6: app

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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))
    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()
开发者ID:rjweir,项目名称:pyramid,代码行数:44,代码来源:__init__.py

示例7: dict

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [as 别名]
import urllib
import json as simplejson

from pyramid.configuration import Configurator
from paste.httpserver import serve

from beaker.cache import cache_regions, cache_region
cache_regions['short_term'] = dict(type='memory', expire=30*60)

def index(request):
    fml_endpoint = 'http://graph.facebook.com/search?q="so%20starving&type=post'
    
    @cache_region('short_term')   
    def fb_data(key=None):
        fb_response = urllib.urlopen(key,).read()
        return simplejson.loads(fb_response)["data"]
        
    return {'data': fb_data(fml_endpoint)}

if __name__ == '__main__':
    settings = {}
    settings['mako.directories'] = './templates'
    config = Configurator(settings=settings)
    config.begin()
    config.add_view(index, name='', renderer='index.mako')
    config.end()
    app = config.make_wsgi_app()
    serve(app, host='0.0.0.0')
开发者ID:klette,项目名称:so-starving,代码行数:30,代码来源:run.py

示例8: hello_world

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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')
开发者ID:thegeekinside,项目名称:pyramid,代码行数:15,代码来源:helloworld.py

示例9: hola_mundo

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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')
开发者ID:dobleub,项目名称:myExperiments,代码行数:19,代码来源:pyramid_basico.py

示例10: app

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [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(root_factory=get_root, settings=settings)
    config.begin()
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)

    tictactroll.gamestate.set_db_path(settings.get('db_path'))

    config.add_view("tictactroll.views.game", name="game",
                    renderer="tictactroll:templates/game.mako")
    config.add_view("tictactroll.views.about", name="about",
                    renderer="tictactroll:templates/about.mako")
    config.add_view("tictactroll.views.welcome",
                    renderer="tictactroll:templates/welcome.mako")
    config.add_view("tictactroll.views.enter_game", name="enter_game")
    config.add_view("tictactroll.views.new_game", name="new_game")

    config.add_view("tictactroll.views.add_grid", name="add_grid",
                    renderer="json")

    config.add_view("tictactroll.views.next_troll_grid",
                    name="next_troll_grid", renderer="json")

    config.add_view("tictactroll.views.gameover_html", name="gameover",
                    renderer="tictactroll:templates/gameover.mako")

    config.add_static_view("static", "tictactroll:static")
    config.end()
    return config.make_wsgi_app()
开发者ID:tamentis,项目名称:tictactroll,代码行数:36,代码来源:__init__.py

示例11: dict

# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import add_view [as 别名]
from pyramid.configuration import Configurator
from paste.httpserver import serve

from beaker.cache import cache_regions, cache_region

cache_regions["short_term"] = dict(type="memory", expire=30 * 60)


def index(request):
    fml_endpoint = 'http://graph.facebook.com/search?q="so%20starving&type=post'

    @cache_region("short_term")
    def fb_data(key=None):
        fb_response = urllib.urlopen(key).read()
        return simplejson.loads(fb_response)["data"]

    return {"data": fb_data(fml_endpoint)}


settings = {}
settings["mako.directories"] = "./templates"
config = Configurator(settings=settings)
config.begin()
config.add_view(index, name="", renderer="index.mako")
config.end()

application = config.make_wsgi_app()

if __name__ == "__main__":
    serve(application, host="0.0.0.0")
开发者ID:pombredanne,项目名称:so-starving,代码行数:32,代码来源:run.py


注:本文中的pyramid.configuration.Configurator.add_view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。