本文整理汇总了Python中pyramid.config.Configurator.add_notfound_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_notfound_view方法的具体用法?Python Configurator.add_notfound_view怎么用?Python Configurator.add_notfound_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_notfound_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.', poolclass=NullPool)
DBSession.configure(bind=engine)
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
Base.metadata.bind = engine
config = Configurator(
settings=settings,
session_factory=my_session_factory,
authentication_policy=SessionAuthenticationPolicy())
Base.metadata.create_all(engine)
config.include('pyramid_chameleon')
config.include('pyramid_jinja2')
config.add_jinja2_search_path("jkh:templates")
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('user', '/user')
config.add_route('news', '/news')
config.add_route('about', '/about')
config.add_route('registration', '/registration')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('passremind', '/passremind')
config.add_route('settings', '/settings')
config.add_notfound_view(not_found, append_slash=True)
config.include('sacrud.pyramid_ext', route_prefix='/admin')
settings = config.registry.settings
settings['sacrud.models'] = {"": [User, Country, Tarif, Service, Region]}
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
"""
This function returns a Pyramid WSGI application.
"""
# the database session:
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
# session_factory = session_factory_from_settings(settings)
config = Configurator(
settings=settings,
root_factory=get_root,
authentication_policy=GyAuthenticationPolicy(),
authorization_policy=GyAuthorizationPolicy(),
session_factory = session_factory_from_settings(settings),
request_factory = GyRequest,
)
config.add_static_view('static', 'static', cache_max_age=3600)
# config.include('pyramid_mailer')
mailer = Mailer.from_settings(settings)
config.registry['mailer'] = mailer
config.include('gy.core')
config.include('gy.blog')
config.add_notfound_view(gy_not_found, append_slash=True)
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
metadata.bind = engine
config = Configurator(settings=settings)
if asbool(settings['debug']):
config.add_static_view('static', path='static/', cache_max_age=1)
config.add_static_view('css', path='static/css/', cache_max_age=1)
config.add_static_view('img', path='static/img/', cache_max_age=1)
config.add_static_view('js', path='static/js/', cache_max_age=1)
config.add_static_view('templates', path='templates/', cache_max_age=1)
# User
config.add_route('users', '/users*args')
config.add_view('confrm.handlers.users.UserHandler', route_name='users')
config.add_route('user_sessions', '/user_sessions*args')
config.add_view('confrm.handlers.user_sessions.UserSessionHandler', route_name='user_sessions')
config.add_route('files', '/files*args')
config.add_view('confrm.handlers.files.FileHandler', route_name='files')
config.add_route('groups', '/groups*args')
config.add_view('confrm.handlers.groups.GroupHandler', route_name='groups')
config.add_notfound_view('confrm.handlers.error404')
config.add_route('root', '/')
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.registry.registerUtility(DBSession, IDBSession)
config.set_authentication_policy(SessionAuthenticationPolicy())
config.set_authorization_policy(ACLAuthorizationPolicy())
# config.scan_horus(models)
config.add_static_view('static', 'static', cache_max_age=3600)
config.scan_horus(models)
config.add_route('index', '/')
config.add_route('course_intro', '/{course}/intro/')
config.add_route('lesson', '/{course}/{lesson}/')
config.add_route('lesson_rest', '/rest/{course}/{lesson}/')
config.add_notfound_view(notfound, append_slash=True)
config.include('horus')
config.include('pyramid_mailer')
# formalchemy
config.include('pyramid_formalchemy')
config.include('pyramid_fanstatic')
config.include('fa.jquery')
# register an admin UI
config.formalchemy_admin('/admin', package='timtec', view='fa.jquery.pyramid.ModelView')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
init_model()
session_factory = session_factory_from_settings(settings)
if 'localization' not in settings:
settings['localization'] = 'id_ID.UTF-8'
locale.setlocale(locale.LC_ALL, settings['localization'])
if 'timezone' not in settings:
settings['timezone'] = DefaultTimeZone
config = Configurator(settings=settings,
root_factory='esipkd.models.RootFactory',
session_factory=session_factory)
config.include('pyramid_beaker')
config.include('pyramid_chameleon')
authn_policy = AuthTktAuthenticationPolicy('sosecret',
callback=group_finder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_title, 'title', reify=True)
config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static')
for name, path, title in routes:
config.add_route(name, path)
config.scan()
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
authentication_policy = AuthenticationPolicy(
settings['auth.secret'], cookie_name='shike.im')
authorization_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings)
config.set_root_factory('hzsxactivitymanagesite.resources.RootFactory')
config.set_authentication_policy(authentication_policy)
config.set_authorization_policy(authorization_policy)
jsonp = JSONP(param_name='callback')
jsonp.add_adapter(ObjectId, objectid_adapter)
jsonp.add_adapter(DBRef, dbref_adapter)
jsonp.add_adapter(datetime.datetime, datetime_adapter)
config.add_renderer('jsonp', jsonp)
config.add_subscriber(real_ip_hook, NewRequest)
config.set_request_property(get_db, "db", reify=True)
config.set_request_property(get_fs, "fs", reify=True)
config.set_request_property(get_user, "user", reify=True)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include("hzsxactivitymanagesite.views.home")
config.add_forbidden_view("hzsxactivitymanagesite.views.forbidden_view", renderer="json")
config.add_notfound_view("hzsxactivitymanagesite.views.notfound_view", renderer="json")
config.add_view("hzsxactivitymanagesite.views.apierror_view", context='hzsxactivitymanagesite.exceptions.APIError', renderer='json')
config.add_view("hzsxactivitymanagesite.views.pageerror_view", context='hzsxactivitymanagesite.exceptions.PageError', renderer='error.mako')
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_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()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory='argusgui.models.RootFactory',
settings=settings)
#authentication_policy=BasicAuthenticationPolicy(mycheck),
#authorization_policy=ACLAuthorizationPolicy())
# renderers
config.add_renderer('jsonp', JSONP(param_name='callback'))
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('image', 'datasets', cache_max_age=3600)
config.add_route('gui_home', '/')
config.add_route('gui_classification', '/classification/')
config.add_route('gui_compare', '/classification/compare/')
config.add_route('gui_test', '/test/')
config.add_route('queue', '/classification/queue/')
config.add_route('train', '/classification/train/{dataset}/')
config.add_route('datasets', '/datasets/')
config.add_route('compare', '/datasets/compare/')
config.add_route('dataset', '/datasets/{dataset}/')
config.add_route('image', '/datasets/{dataset}/{image}/')
config.add_notfound_view(not_found, append_slash=True)
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('cornice')
# templates
config.add_notfound_view(notfound, append_slash=False)
config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
config.add_renderer('.jinja2', 'pyramid_jinja2.renderer_factory')
config.add_jinja2_search_path('templates')
# apps
config.include('main')
config.include('businesses', route_prefix='/api/v1')
config.include('reviews', route_prefix='/api/v1')
config.include('auth', route_prefix='/api/v1')
# static files
config.add_route('catchall_static', '/*subpath')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_view('service.static.static_view', route_name='catchall_static')
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
add_directives(config)
authn_policy = BasicAuthAuthenticationPolicy(check=auth_check_func)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('browse', '/browse')
config.add_route('simple', '/simple*traverse', factory=repository_root_factory)
config.add_notfound_view(notfound, append_slash=True)
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
assets_env = config.get_webassets_env()
config.commit()
jinja2_env = config.get_jinja2_environment()
jinja2_env.assets_environment = assets_env
# config.add_webasset('test', jst)
config.add_webasset('papaye_js', papaye_js)
config.add_webasset('papaye_css', papaye_css)
config.add_webasset('papaye_font', papaye_font)
config.check_database_config()
config.scan()
config.start_scheduler()
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('hello', '/')
config.add_route('hello_you', '/nombre/{name}')
config.add_view(hello_pyramid, route_name='hello')
config.add_view(hello_you, route_name='hello_you')
config.add_notfound_view(not_found)
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
#engine.echo = True
DBSession.configure(bind=engine)
Base.metadata.bind = engine
init_model()
session_factory = session_factory_from_settings(settings)
if 'localization' not in settings:
settings['localization'] = 'id_ID.UTF-8'
locale.setlocale(locale.LC_ALL, settings['localization'])
if 'timezone' not in settings:
settings['timezone'] = DefaultTimeZone
config = Configurator(settings=settings,
root_factory='egaji.models.RootFactory',
session_factory=session_factory)
config.include('pyramid_beaker')
config.include('pyramid_chameleon')
authn_policy = AuthTktAuthenticationPolicy('sosecret',
callback=group_finder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_title, 'title', reify=True)
config.add_request_method(get_months, 'months', reify=True)
config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static')
config.add_renderer('csv', '.tools.CSVRenderer')
#routes = DBSession.query(RouteModel.kode, RouteModel.path, RouteModel.nama, RouteModel.factory).all()
"""
for route in routes:
if route.factory:
config.add_route(route.kode, route.path, factory=(route.factory).encode("utf8"))
else:
config.add_route(route.kode, route.path)
"""
# if route.nama:
# titles[route.kode] = route.nama #' - '.join([main_title, title])
for name, path, title, factory in routes:
if factory:
config.add_route(name, path, factory=factory)
else:
config.add_route(name, path)
if name:
titles[name] = ' - '.join([path, title])
print list(title)
config.scan()
return config.make_wsgi_app()
示例13: create_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def create_app(settings, instrument):
"""Return a pyramid wsgi app"""
def index(request):
return Response('idx')
def error(request):
raise HTTPInternalServerError("oh no")
def exception(request):
1 / 0
def json(request):
return {'a': 1}
def renderer(request):
return render_to_response('template.pt', {'foo': 'bar'}, request=request)
def raise_redirect(request):
raise HTTPFound()
def raise_no_content(request):
raise HTTPNoContent()
def custom_exception_view(context, request):
"""Custom view that forces a HTTPException when no views
are found to handle given request
"""
if 'raise_exception' in request.url:
raise HTTPNotFound()
else:
return HTTPNotFound()
config = Configurator(settings=settings)
config.add_route('index', '/')
config.add_route('error', '/error')
config.add_route('exception', '/exception')
config.add_route('json', '/json')
config.add_route('renderer', '/renderer')
config.add_route('raise_redirect', '/redirect')
config.add_route('raise_no_content', '/nocontent')
config.add_view(index, route_name='index')
config.add_view(error, route_name='error')
config.add_view(exception, route_name='exception')
config.add_view(json, route_name='json', renderer='json')
config.add_view(renderer, route_name='renderer', renderer='template.pt')
config.add_view(raise_redirect, route_name='raise_redirect')
config.add_view(raise_no_content, route_name='raise_no_content')
# required to reproduce a regression test
config.add_notfound_view(custom_exception_view)
# required for rendering tests
renderer = config.testing_add_renderer('template.pt')
if instrument:
trace_pyramid(config)
return config.make_wsgi_app(), renderer
示例14: __init__
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def __init__(self, *args, **settings):
if len(args) == 1:
# regular app
app = None
else:
app = args[0]
self.initialize_settings(app, settings)
# db configuration
db_factory_name = settings.get('db_factory_name', 'sql')
if db_factory_name not in db_factories:
raise Exception("Invalid db_factory_name: %s" % db_factory_name)
settings['db_session_id'], self.db = db_factories[db_factory_name](settings, self) # noqa
self.setup_autouserfinder(settings)
# start pyramid application configuration
config = Configurator(settings=settings, request_factory=Request)
try:
import pyramid_chameleon # noqa
config.include('pyramid_chameleon')
except ImportError:
pass
self.setup_plugins(config, settings)
from factored.views import auth_chooser, notfound
config.add_route('auth', self.base_auth_url)
config.add_view(auth_chooser, route_name='auth',
renderer='templates/layout.pt')
# setup template customization registration
if TEMPLATE_CUSTOMIZATIONS not in config.registry:
config.registry[TEMPLATE_CUSTOMIZATIONS] = {}
# static paths for resources
self.static_path = os.path.join(self.base_auth_url, 'authstatic')
config.add_static_view(name=self.static_path,
path='factored:static')
config.add_notfound_view(notfound, append_slash=True)
# add some things to registry
config.registry['mailer'] = Mailer.from_settings(settings)
config.registry['settings'] = self.__dict__
config.registry['formtext'] = nested_settings(
get_settings(settings, 'formtext.'))
config.registry['app'] = self
config.scan()
self.config = config
self.registry = self.config.registry
try:
self.app.config.registry['factored'] = self
except:
pass
self.pyramid = config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_notfound_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
init_model()
############################################################################
#json_renderer = JSON()
#json_renderer.add_adapter(datetime.datetime, lambda v: v.isoformat())
###########################################################################
session_factory = session_factory_from_settings(settings)
if 'localization' not in settings:
settings['localization'] = 'id_ID.UTF-8'
locale.setlocale(locale.LC_ALL, settings['localization'])
if 'timezone' not in settings:
settings['timezone'] = DefaultTimeZone
config = Configurator(settings=settings,
root_factory='ipbb.models.RootFactory',
session_factory=session_factory)
config.include('pyramid_beaker')
config.include('pyramid_chameleon')
############################################################################
config.include('pyramid_rpc.jsonrpc') # JSON RPC
#config.add_renderer('json', json_renderer)
############################################################################
authn_policy = AuthTktAuthenticationPolicy('sosecret',
callback=group_finder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_title, 'title', reify=True)
config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static')
config.add_renderer('csv', '.tools.CSVRenderer')
routes = DBSession.query(Route.kode, Route.path, Route.nama).all()
for route in routes:
config.add_route(route.kode, route.path)
if route.nama:
titles[route.kode] = ' - '.join([main_title, route.nama])
config.add_jsonrpc_endpoint('pbb', '/pbb') #, default_renderer="json")
config.scan()
return config.make_wsgi_app()