Example #1
0
def render_template(request, template_path, context):
    """
    Render a template with context.

    Always inserts the request into the context, so you don't have to.
    Also stores the context if we're doing unit tests.  Helpful!
    """
    template = request.template_env.get_template(template_path)
    context['request'] = request
    rendered_csrf_token = render_csrf_form_token(request)
    if rendered_csrf_token is not None:
        context['csrf_token'] = render_csrf_form_token(request)

    # allow plugins to do things to the context
    if request.controller_name:
        context = hook_transform((request.controller_name, template_path),
                                 context)

    # More evil: allow plugins to possibly do something to the context
    # in every request ever with access to the request and other
    # variables.  Note: this is slower than using
    # template_global_context
    context = hook_transform('template_context_prerender', context)

    rendered = template.render(context)

    if common.TESTS_ENABLED:
        TEMPLATE_TEST_CONTEXT[template_path] = context

    return rendered
Example #2
0
def render_template(request, template_path, context):
    """
    Render a template with context.

    Always inserts the request into the context, so you don't have to.
    Also stores the context if we're doing unit tests.  Helpful!
    """
    template = request.template_env.get_template(
        template_path)
    context['request'] = request
    rendered_csrf_token = render_csrf_form_token(request)
    if rendered_csrf_token is not None:
        context['csrf_token'] = render_csrf_form_token(request)

    # allow plugins to do things to the context
    if request.controller_name:
        context = hook_transform(
            (request.controller_name, template_path),
            context)

    # More evil: allow plugins to possibly do something to the context
    # in every request ever with access to the request and other
    # variables.  Note: this is slower than using
    # template_global_context
    context = hook_transform(
        'template_context_prerender', context)

    rendered = template.render(context)

    if common.TESTS_ENABLED:
        TEMPLATE_TEST_CONTEXT[template_path] = context

    return rendered
Example #3
0
def render_template(request, template_path, context):
    """
    Render a template with context.

    Always inserts the request into the context, so you don't have to.
    Also stores the context if we're doing unit tests.  Helpful!
    """
    template = request.template_env.get_template(
        template_path)
    context['request'] = request
    rendered_csrf_token = render_csrf_form_token(request)
    if rendered_csrf_token is not None:
        context['csrf_token'] = render_csrf_form_token(request)
    rendered = template.render(context)

    if common.TESTS_ENABLED:
        TEMPLATE_TEST_CONTEXT[template_path] = context

    return rendered