__init__.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:jinja2-sanic 作者: yunstanford 项目源码 文件源码
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
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号