def isactive(context, url, active='active', inactive='', exact=False):
    """
    A ternary tag for whether a URL is 'active'. An active URL is defined as matching
    the current request URL. The default behavior is to match the beginning of the URL.
    For example, if `url` is '/some/path' and the current request URL is
    '/some/path/subpath', then the URL is considered active. If `exact` is set to True,
    then the URL's must match exactly.

    Example::

        {% url 'named-url' as named_url %}
        <div class="{% isactive named_url 'active' 'inactive' %}">
        </div>

    """
    request_url = context['request'].path_info
    if (request_url == url if exact else request_url.startswith(url)):
        return active
    return inactive