本文整理汇总了Python中werkzeug.wsgi.SharedDataMiddleware方法的典型用法代码示例。如果您正苦于以下问题:Python wsgi.SharedDataMiddleware方法的具体用法?Python wsgi.SharedDataMiddleware怎么用?Python wsgi.SharedDataMiddleware使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.wsgi
的用法示例。
在下文中一共展示了wsgi.SharedDataMiddleware方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap_static
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def wrap_static(self):
'''Adds a "/static" route for static files.
This should only be used for the development server. Production servers
should expose the /static directory directly.
'''
self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {
'/static': os.path.join(os.path.dirname(__file__), 'static')
})
示例2: __init__
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def __init__(
self,
presentation,
config=None,
media=None,
theme=None,
style=None,
reloader=False,
):
"""
Initializes the server and creates the environment for the presentation
"""
self.config = Config(config)
self.presentation = presentation
self.reloader = reloader
shared_data = {
"/static": os.path.join(os.path.dirname(__file__), "static")
}
shared_data.update(self.parse_shared_data(media))
shared_data.update(self.parse_shared_data(theme))
if style:
self.style = os.path.basename(style)
shared_data.update(self.parse_shared_data(style))
else:
self.style = None
self.wsgi_app = SharedDataMiddleware(self.wsgi_app, shared_data)
示例3: create_app
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def create_app(redis_host='localhost', redis_port=6379, with_static=True):
app = Shortly({
'redis_host': redis_host,
'redis_port': redis_port
})
if with_static:
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/static': os.path.join(os.path.dirname(__file__), 'static')
})
return app
示例4: test_shareddatamiddleware_get_file_loader
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def test_shareddatamiddleware_get_file_loader(self):
app = wsgi.SharedDataMiddleware(None, {})
assert callable(app.get_file_loader('foo'))
示例5: test_shared_data_middleware
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def test_shared_data_middleware(self):
def null_application(environ, start_response):
start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
yield b'NOT FOUND'
test_dir = get_temporary_directory()
with open(path.join(test_dir, to_native(u'äöü', 'utf-8')), 'w') as test_file:
test_file.write(u'FOUND')
app = wsgi.SharedDataMiddleware(null_application, {
'/': path.join(path.dirname(__file__), 'res'),
'/sources': path.join(path.dirname(__file__), 'res'),
'/pkg': ('werkzeug.debug', 'shared'),
'/foo': test_dir
})
for p in '/test.txt', '/sources/test.txt', '/foo/äöü':
app_iter, status, headers = run_wsgi_app(app, create_environ(p))
self.assert_equal(status, '200 OK')
with closing(app_iter) as app_iter:
data = b''.join(app_iter).strip()
self.assert_equal(data, b'FOUND')
app_iter, status, headers = run_wsgi_app(
app, create_environ('/pkg/debugger.js'))
with closing(app_iter) as app_iter:
contents = b''.join(app_iter)
self.assert_in(b'$(function() {', contents)
app_iter, status, headers = run_wsgi_app(
app, create_environ('/missing'))
self.assert_equal(status, '404 NOT FOUND')
self.assert_equal(b''.join(app_iter).strip(), b'NOT FOUND')
示例6: create_app
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def create_app():
"""Create Flask app."""
config = load_config()
app = Flask(__name__)
app.config.from_object(config)
if not hasattr(app, 'production'):
app.production = not app.debug and not app.testing
# Proxy fix
app.wsgi_app = ProxyFix(app.wsgi_app)
# CSRF protect
CsrfProtect(app)
if app.debug or app.testing:
DebugToolbarExtension(app)
# Serve static files
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/pages': os.path.join(app.config.get('PROJECT_PATH'), 'application/pages')
})
else:
# Log errors to stderr in production mode
app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.ERROR)
# Enable Sentry
if app.config.get('SENTRY_DSN'):
from .utils.sentry import sentry
sentry.init_app(app, dsn=app.config.get('SENTRY_DSN'))
# Serve static files
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/static': os.path.join(app.config.get('PROJECT_PATH'), 'output/static'),
'/pkg': os.path.join(app.config.get('PROJECT_PATH'), 'output/pkg'),
'/pages': os.path.join(app.config.get('PROJECT_PATH'), 'output/pages')
})
# Register components
register_db(app)
register_routes(app)
register_jinja(app)
register_error_handle(app)
register_hooks(app)
return app
示例7: create_app
# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import SharedDataMiddleware [as 别名]
def create_app():
"""Create Flask app."""
config = load_config()
app = Flask(__name__)
app.config.from_object(config)
# Proxy fix
app.wsgi_app = ProxyFix(app.wsgi_app)
# CSRF protect
CsrfProtect(app)
if app.debug or app.testing:
DebugToolbarExtension(app)
# Serve static files
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/pages': os.path.join(app.config.get('PROJECT_PATH'), 'application/pages')
})
else:
# Log errors to stderr in production mode
app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.ERROR)
# Enable Sentry
if app.config.get('SENTRY_DSN'):
from .utils.sentry import sentry
sentry.init_app(app, dsn=app.config.get('SENTRY_DSN'))
# Serve static files
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/static': os.path.join(app.config.get('PROJECT_PATH'), 'output/static'),
'/pkg': os.path.join(app.config.get('PROJECT_PATH'), 'output/pkg'),
'/pages': os.path.join(app.config.get('PROJECT_PATH'), 'output/pages')
})
# Register components
register_db(app)
register_routes(app)
register_jinja(app)
register_error_handle(app)
register_hooks(app)
return app