class Application(WSGIApplication): def initialize(self, root_dir): self.root_dir = root_dir # routing self.router = Router() self.router.add( StaticDirectoryRoute('/css/', join(self.root_dir, 'static/css')), StaticDirectoryRoute('/img/', join(self.root_dir, 'static/img')), StaticDirectoryRoute('/js/', join(self.root_dir, 'static/js')), Route('/', self.index), ) # templating self.template_loader = TemplateLoader(join(self.root_dir, 'template')) def handle_request(self, request): return self.router.handle_request(request) def render_html(self, html, content_type='text/html'): return self.Response(html, content_type=content_type) def render(self, template_name, content_type='text/html', **kwargs): template = self.template_loader.load(template_name) return self.Response(template.render(**kwargs), content_type=content_type) def index(self, request): return self.render('index.html')
def initialize(self, root_dir): self.root_dir = root_dir # routing self.router = Router() self.router.add( StaticDirectoryRoute('/css/', join(self.root_dir, 'static/css')), StaticDirectoryRoute('/img/', join(self.root_dir, 'static/img')), StaticDirectoryRoute('/js/', join(self.root_dir, 'static/js')), Route('/', self.index), ) # templating self.template_loader = TemplateLoader(join(self.root_dir, 'template'))