'Renders the template with the given arguments as the response.'

def render(self, template_name, **kwargs):

    html = self.render_string(template_name, **kwargs)
    js_embed = []
    js_files = []
    css_embed = []
    css_files = []
    html_heads = []
    html_bodies = []
    for module in getattr(self, '_active_modules', {}).values():
        embed_part = module.embedded_javascript()
        if embed_part:
            js_embed.append(utf8(embed_part))
        file_part = module.javascript_files()
        if file_part:
            if isinstance(file_part, (unicode_type, bytes)):
                js_files.append(file_part)
            else:
                js_files.extend(file_part)
        embed_part = module.embedded_css()
        if embed_part:
            css_embed.append(utf8(embed_part))
        file_part = module.css_files()
        if file_part:
            if isinstance(file_part, (unicode_type, bytes)):
                css_files.append(file_part)
            else:
                css_files.extend(file_part)
        head_part = module.html_head()
        if head_part:
            html_heads.append(utf8(head_part))
        body_part = module.html_body()
        if body_part:
            html_bodies.append(utf8(body_part))
    def is_absolute(path):
        return any((path.startswith(x) for x in ['/', 'http:', 'https:']))
    if js_files:
        paths = []
        unique_paths = set()
        for path in js_files:
            if (not is_absolute(path)):
                path = self.static_url(path)
            if (path not in unique_paths):
                paths.append(path)
                unique_paths.add(path)
        js = ''.join(((('<script    src="' + escape.xhtml_escape(p)) + '"    type="text/javascript"></script>') for p in paths))
        sloc = html.rindex('</body>')
        html = (((html[:sloc] + utf8(js)) + '\n') + html[sloc:])
    if js_embed:
        js = (('<script    type="text/javascript">\n//<![CDATA[\n' + '\n'.join(js_embed)) + '\n//]]>\n</script>')
        sloc = html.rindex('</body>')
        html = (((html[:sloc] + js) + '\n') + html[sloc:])
    if css_files:
        paths = []
        unique_paths = set()
        for path in css_files:
            if (not is_absolute(path)):
                path = self.static_url(path)
            if (path not in unique_paths):
                paths.append(path)
                unique_paths.add(path)
        css = ''.join(((('<link    href="' + escape.xhtml_escape(p)) + '"    type="text/css"    rel="stylesheet"/>') for p in paths))
        hloc = html.index('</head>')
        html = (((html[:hloc] + utf8(css)) + '\n') + html[hloc:])
    if css_embed:
        css = (('<style    type="text/css">\n' + '\n'.join(css_embed)) + '\n</style>')
        hloc = html.index('</head>')
        html = (((html[:hloc] + css) + '\n') + html[hloc:])
    if html_heads:
        hloc = html.index('</head>')
        html = (((html[:hloc] + ''.join(html_heads)) + '\n') + html[hloc:])
    if html_bodies:
        hloc = html.index('</body>')
        html = (((html[:hloc] + ''.join(html_bodies)) + '\n') + html[hloc:])
    self.finish(html)
