本文整理汇总了Python中pyramid.config.Configurator.add_static_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_static_view方法的具体用法?Python Configurator.add_static_view怎么用?Python Configurator.add_static_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_static_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
load_project_settings()
session_factory = UnencryptedCookieSessionFactoryConfig(settings.get('session.secret', 'hello'))
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
config = Configurator(session_factory=session_factory, settings=settings)
config.include('pyramid_handlers')
config.add_view('pyramid.view.append_slash_notfound_view',
context='pyramid.httpexceptions.HTTPNotFound')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('status', '/status')
config.add_route('settings', '/settings')
configure_app_routes(config)
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
session_factory = UnencryptedCookieSessionFactoryConfig('nilsbysite')
config = Configurator(settings=settings, session_factory=session_factory)
config.add_static_view('static', 'nilsby:static', cache_max_age=3600)
# Auth routes
config.add_route('user_new', '/signup')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
# Forum routes
config.add_route('forum_index', '/forum')
config.add_route('forum_view', '/forum/view/{id}')
config.add_route('forum_post', '/forum/post')
config.add_route('forum_reply', '/forum/reply/{post_id}')
# User routes
config.add_route('user_index', '/users')
config.add_route('user_view', '/user/view/{id}')
# Home route
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_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
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('drink_page', '/drink/{item_id}')
config.add_route('user_redirect', '/user')
config.add_route('user_page', '/user/{username}')
config.add_route('machine_page', '/machine/{machine_id}')
config.add_route('autocomplete', '/autocomplete')
config.add_route('drink_redirect', '/fordrink')
config.add_route('api_item_usage', '/api/drink/{item_id}')
config.add_route('api_user_usage', '/api/user/{username}')
config.add_route('api_machine_usage', '/api/machine/{machine_id}')
config.add_route('api_total_usage', '/api/total')
config.add_route('api_pop_hours', '/api/hours')
config.scan()
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_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
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings,
root_factory='tutorial.models.RootFactory')
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('view_wiki', '/')
config.add_route('books', '/books')
config.add_route('amazon_info', '/amazon_info')
config.add_route('books_info', '/books_info')
config.add_route('question', '/question')
config.add_route('check_answer', '/check_answer')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('view_page', '/{pagename}')
config.add_route('add_page', '/add_page/{pagename}')
config.add_route('edit_page', '/{pagename}/edit_page')
config.scan()
return config.make_wsgi_app()
示例5: Test_static_url_filter
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
class Test_static_url_filter(unittest.TestCase):
def setUp(self):
self.environment = Environment()
from pyramid_jinja2.filters import static_url_filter
self.environment.filters['static_url'] = static_url_filter
from pyramid.config import Configurator
self.config = Configurator(autocommit=True)
self.config.begin(request=DummyRequest())
self.config.add_static_view('myfiles', 'dummy1:static')
self.config.add_static_view('otherfiles/{owner}', 'dummy2:files')
def tearDown(self):
self.config.end()
def _callFUT(self, context, tmpl):
tmpl = self.environment.from_string(tmpl)
return tmpl.render(**context)
def test_filter(self):
rendered = self._callFUT({}, "{{'dummy1:static/the/quick/brown/fox.svg' | static_url }}")
self.assertEqual(rendered, 'http://example.com/myfiles/the/quick/brown/fox.svg')
def test_filter_with_arguments(self):
rendered = self._callFUT({}, "{{'dummy2:files/report.txt' | static_url(owner='foo') }}")
self.assertEqual(rendered, 'http://example.com/otherfiles/foo/report.txt')
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include(install_html_mako)
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_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
authn_policy = AuthTktAuthenticationPolicy('sosecret')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory = Factory
)
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('home', '/')
config.add_route('search','/search')
config.add_route('history', '/history')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('register', '/register')
config.add_route('user_list', '/user_list')
config.add_route('top_search', '/top_search')
config.add_route('jsonview', '/json')
config.add_request_method(get_user, 'user', reify = True)
config.scan()
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
authentication_policy = AuthTktAuthenticationPolicy('lrrrftht', callback=groupfinder)
authorization_policy = ACLAuthorizationPolicy()
config = Configurator(authentication_policy=authentication_policy, authorization_policy=authorization_policy, settings=settings, root_factory='datinggame.models.RootFactory')
#set up the database and have it append to each request
db_uri = settings['db_uri']
conn = pymongo.Connection(db_uri)
config.registry.settings['db_conn'] = conn
config.add_subscriber(add_mongo_db, NewRequest)
config.add_static_view('static', 'datinggame:static', cache_max_age=3600)
#add the routes here -- they will be specified with a decorator in the views file
config.add_route('root', '')
config.add_route('logout', '/logout')
config.add_route('login', '/login')
config.add_route('start', '/start')
config.add_route('signup', '/signup')
config.add_route('edit','/edit')
config.add_route('editpicture','/editpicture')
config.add_route('profilepic','/profilepic/{pic_id}')
config.add_route('messagethread', '/messages/{username}')
config.add_route('favicon', "/favicon.ico")
config.add_route('user', '/{username}')
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=getAppRoot, settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
# authnPolicy = BasicAuthAuthenticationPolicy(check=checkAuthentication,
# realm='Djosr Login') #, debug=True)
authnPolicy = AuthTktAuthenticationPolicy(secret='not telling',
callback=getGroups)#, debug=True)
authzPolicy = ACLAuthorizationPolicy()
config.set_authentication_policy(authnPolicy)
config.set_authorization_policy(authzPolicy)
sessFactory = UnencryptedCookieSessionFactoryConfig('not telling')
config.set_session_factory(sessFactory)
config.add_request_method(getUser, 'user', reify=True)
config.scan()
# this saves having to do a GET to catch simple bugs
# TODO remove later when code is bug-free ;-)
from pyramid.testing import DummyRequest
dummy = DummyRequest()
dummy.registry = config.registry
getAppRoot(dummy)
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
"""This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=root_factory, settings=settings)
config.add_static_view("static", "static", cache_max_age=3600)
config.add_route("update", "/update")
config.add_view(UpdateItems, route_name="update")
config.add_route("update_deletions", "/update_deletions")
config.add_view(update_deletions, route_name="update_deletions")
config.add_route("delete", "/delete")
config.add_view(delete_items, route_name="delete")
config.add_route("shared", "/global-shared.xml")
config.add_view(global_shared, route_name="shared")
config.add_route("selected", "/global-selected.xml")
config.add_view(global_selected, route_name="selected")
config.add_route("deleted", "global-deletions.xml")
config.add_view(global_deleted, route_name="deleted")
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
initialize_sql(engine)
config = Configurator(settings=settings, session_factory = my_session_factory)
config.add_static_view('static', 'useradmin:static', cache_max_age=3600)
config.add_route('na', '/')
config.add_route('index', '/index')
config.add_route('logout', '/logout')
config.add_route('REST_listing', '/REST/admin/listing')
config.add_route('REST_create', '/REST/admin/create/{type}')
config.add_route('REST_get', '/REST/admin/get/{type}')
config.add_route('REST_edit', '/REST/admin/edit/{type}/{id}')
config.add_route('REST_view', '/REST/admin/view/{type}/{id}')
config.add_route('REST_delete', '/REST/admin/delete/{type}/{id}')
config.add_route('REST_error', '/REST/admin/error/{id}')
config.add_view('useradmin.views.index', route_name='na', renderer='templates/index.pt')
config.add_view('useradmin.views.index', route_name='index', renderer='templates/index.pt')
config.add_view('useradmin.views.logout', route_name='logout')
config.add_view('useradmin.rest.listing', route_name='REST_listing', renderer='json', request_method='GET')
config.add_view('useradmin.rest.create', route_name='REST_create', renderer='json', request_method='POST')
config.add_view('useradmin.rest.get', route_name='REST_get', renderer='json', request_method='GET')
config.add_view('useradmin.rest.edit', route_name='REST_edit', renderer='json', request_method='POST')
config.add_view('useradmin.rest.view', route_name='REST_view', renderer='json', request_method='GET')
config.add_view('useradmin.rest.delete', route_name='REST_delete', renderer='json', request_method='GET')
config.add_view('useradmin.rest.error', route_name='REST_error', renderer='json', request_method='GET')
return config.make_wsgi_app()
示例12: app_factory
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def app_factory(global_config, **settings):
"""Setup the main application for paste
This must be setup as the paste.app_factory in the egg entry-points.
"""
authn_policy = AuthTktAuthenticationPolicy(
settings['auth.secret'],
# 30 days age for the session cookie
max_age=60 * 60 * 24 * 30,
reissue_time=60 * 60 * 24,
)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
root_factory=Root,
autocommit=True,
)
config.include('eta.service', route_prefix='/api/v1')
config.scan('eta.service')
config.add_static_view('', '../static')
init_db(config)
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy('secretstring',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, session_factory=session_factory,
root_factory='portfolio.models.permissions.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.include('pyramid_chameleon')
config.include('pyramid_beaker')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('list_user', '/list_user/')
config.add_route('ajax_user', '/ajax_user/')
config.add_route('datatable','/datatable/')
config.add_route('download','/download/{id_doc}')
get_routes(config)
config.scan()
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('s4u.sqlalchemy')
config.include('s4u.image')
config.set_root_factory(DefaultRoot)
config.set_authentication_policy(
AuthTktAuthenticationPolicy('photoshare',
include_ip=False,
max_age=60 * 60 * 24 * 7,
timeout=60 * 60 * 24 * 7,
reissue_time=60 * 60 * 24,
http_only=True))
config.set_authorization_policy(
ACLAuthorizationPolicy())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('upload', '/upload')
config.add_route('browse', '/browse')
config.add_route('browse-user', '/browse/{id:\d+}',
factory=user_factory)
config.add_route('download-user', '/browse/{id:\d+}/download',
factory=user_factory)
config.add_route('download-photo', '/api/photo/{id:\d+}/download',
factory=photo_factory)
config.add_route('delete-photo', '/api/photo/{id:\d+}/delete',
factory=photo_factory)
config.scan()
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_static_view [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
config = Configurator(
settings=settings,
request_factory=RequestWithDBAttribute,
)
config.begin()
config.scan('sawhoosh.model')
initialize_sql(engine)
config.add_route('index', '')
config.add_route('search', '/search')
config.add_route('author_new', '/author/new')
config.add_route('author_edit', '/author/{id}/edit')
config.add_route('author_instance', pattern='/author/{id}')
config.add_route('author', pattern='/author')
config.add_route('document_new', '/document/new')
config.add_route('document_edit', '/document/{id}/edit')
config.add_route('document_instance', pattern='/document/{id}')
config.add_route('document', pattern='/document')
config.add_static_view('static', 'sawhoosh:static')
config.scan('sawhoosh.views')
config.end()
return HttpMethodOverrideMiddleware(config.make_wsgi_app())