コード例 #1
0
from my_django.conf import settings
from my_django.template import Library

register = Library()

if 'my_django.contrib.staticfiles' in settings.INSTALLED_APPS:
    from my_django.contrib.staticfiles.templatetags.staticfiles import static
else:
    from my_django.templatetags.static import static

static = register.simple_tag(static)
コード例 #2
0
from my_django.template import Library, TemplateSyntaxError
from my_django.template.defaulttags import kwarg_re, SsiNode, URLNode

register = Library()

@register.tag
def ssi(parser, token):
    """
    Outputs the contents of a given file into the page.

    Like a simple "include" tag, the ``ssi`` tag includes the contents
    of another file -- which must be specified using an absolute path --
    in the current page::

        {% ssi "/home/html/ljworld.com/includes/right_generic.html" %}

    If the optional "parsed" parameter is given, the contents of the included
    file are evaluated as template code, with the current context::

        {% ssi "/home/html/ljworld.com/includes/right_generic.html" parsed %}
    """
    bits = token.split_contents()
    parsed = False
    if len(bits) not in (2, 3):
        raise TemplateSyntaxError("'ssi' tag takes one argument: the path to"
                                  " the file to be included")
    if len(bits) == 3:
        if bits[2] == 'parsed':
            parsed = True
        else:
            raise TemplateSyntaxError("Second (optional) argument to %s tag"