使いたいですwebob.static.DirectoryApp
。私はそれを行う方法を理解できません:
http://docs.webob.org/en/latest/file-example.htmlの例から、ルーターは次のようになります。
class Router(object):
def __init__(self, static_path=None):
self.routes = []
self.static_path = static_path if static_path is not None else os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static')
self.static_app = DirectoryApp(self.static_path)
def add_route(self, template, controller, **vars):
if isinstance(controller, basestring):
controller = load_controller(controller)
self.routes.append((re.compile(template_to_regex(template)),
controller,
vars))
def __call__(self, environ, start_response):
req = Request(environ)
for regex, controller, vars in self.routes:
match = regex.match(req.path_info)
if match:
req.urlvars = match.groupdict()
req.urlvars.update(vars)
return controller(environ, start_response)
return exc.HTTPNotFound()(environ, start_response)
提供するアプリケーションを作成するには:
def create_app():
router = Router()
#router.add_route('/', controller='app.controllers.default:index')
router.add_route('/', controller=default.index)
return router
これにより、追加したコントローラーへのルートが正常に提供されます。も追加しましたself.static_app
。
static
-folderから静的ファイルを提供するためにそれを使用する方法がわかりません! 誰かが私を啓発してもらえますか?