def serve_schema_js(schema: APISchema, templates: Templates) -> http.Response: codec = CoreJSONCodec() base64_schema = base64.b64encode(codec.encode(schema)).decode('latin1') template = templates.get_template('apistar/schema.js') content = template.render(base64_schema=base64_schema) headers = {'Content-Type': 'application/javascript'} return http.Response(content, headers=headers)
def serve_docs(schema: APISchema, templates: Templates, path: Path): index = templates.get_template('apistar/docs/index.html') langs = ['python', 'javascript', 'shell'] def static(path): return '/static/' + path def get_fields(link, location): return [field for field in link.fields if field.location == location] return index.render(document=schema, static=static, langs=langs, get_fields=get_fields, render_form=render_form, path=path)
def serve_docs(schema: APISchema, templates: Templates, path: Path): index = templates.get_template('apistar/docs/index.html') langs = ['python', 'javascript', 'shell'] def static(path): return '/static/' + path def get_fields(link, location): return [ field for field in link.fields if field.location == location ] return index.render( document=schema, static=static, langs=langs, get_fields=get_fields, render_form=render_form, path=path )
def get_and_render_template(username: str, templates: Templates): index = templates.get_template('index.html') return index.render(username=username)