def pjax(template_names, request, default="pjax_base.html"):
    """
    Returns template name for request.

    :param request: Django request or boolean value
    :param template_names: Base theme name or comma-separated names of base and
      pjax templates.

    Examples::

        {% extends "base.html"|pjax:request %}
        {% extends "base.html,pjax_base.html"|pjax:request %}

        context = {"is_pjax": True}
        {% extends "base.html"|pjax:is_pjax %}
    """
    if isinstance(request, (bool, int)):
        is_pjax = request
    else:
        is_pjax = request.META.get("HTTP_X_PJAX", False)

    if "," in template_names:
        template_name, pjax_template_name = template_names.split(",", 1)
    else:
        template_name, pjax_template_name = template_names, default

    if is_pjax:
        return pjax_template_name.strip() or default
    return template_name.strip()