def render_template(template_name, request, context, *,
app_key=APP_KEY, encoding='utf-8',
headers=None, status=200):
"""
Return sanic.response.Response which contains template template_name filled with context.
Returned response has Content-Type header set to 'text/html'.
:param template_name: template name.
:param request: a parameter from web-handler, sanic.request.Request instance.
:param context: context for rendering.
:param encoding: response encoding, 'utf-8' by default.
:param status: HTTP status code for returned response, 200 (OK) by default.
:param app_key: a optional key for application instance. If not provided,
default value will be used.
"""
if context is None:
context = {}
text = render_string(template_name, request, context, app_key=app_key)
content_type = "text/html; charset={encoding}".format(encoding=encoding)
return HTTPResponse(
text, status=status, headers=headers,
content_type=content_type
)
评论列表
文章目录