django.template.TemplateSyntaxError

Here are the examples of the python api django.template.TemplateSyntaxError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

182 Examples 7

3 Source : xadmin_tags.py
with GNU General Public License v3.0
from abaoMAO

def do_blockcapture(parser, token):
    try:
        tag_name, args = token.contents.split(None, 1)
    except ValueError:
        raise template.TemplateSyntaxError("'blockcapture' node requires a variable name.")

    nodelist = parser.parse(('endblockcapture',))
    parser.delete_first_token()

    return BlockcaptureNode(nodelist, args)

3 Source : jinja2.py
with GNU General Public License v3.0
from Aghoreshwar

    def get_template(self, template_name):
        try:
            return Template(self.env.get_template(template_name), self)
        except jinja2.TemplateNotFound as exc:
            raise TemplateDoesNotExist(exc.name, backend=self) from exc
        except jinja2.TemplateSyntaxError as exc:
            new = TemplateSyntaxError(exc.args)
            new.template_debug = get_exception_info(exc)
            raise new from exc

    @cached_property

3 Source : i18n.py
with GNU General Public License v3.0
from Aghoreshwar

def language(parser, token):
    """
    This will enable the given language just for this block.

    Usage::

        {% language "de" %}
            This is {{ bar }} and {{ boo }}.
        {% endlanguage %}
    """
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes one argument (language)" % bits[0])
    language = parser.compile_filter(bits[1])
    nodelist = parser.parse(('endlanguage',))
    parser.delete_first_token()
    return LanguageNode(nodelist, language)

3 Source : static.py
with GNU General Public License v3.0
from Aghoreshwar

    def __init__(self, varname=None, name=None):
        if name is None:
            raise template.TemplateSyntaxError(
                "Prefix nodes must be given a name to return.")
        self.varname = varname
        self.name = name

    @classmethod

3 Source : static.py
with GNU General Public License v3.0
from Aghoreshwar

    def handle_token(cls, parser, token, name):
        """
        Class method to parse prefix node and return a Node.
        """
        # token.split_contents() isn't useful here because tags using this method don't accept variable as arguments
        tokens = token.contents.split()
        if len(tokens) > 1 and tokens[1] != 'as':
            raise template.TemplateSyntaxError(
                "First argument in '%s' must be 'as'" % tokens[0])
        if len(tokens) > 1:
            varname = tokens[2]
        else:
            varname = None
        return cls(varname, name)

    @classmethod

3 Source : static.py
with GNU General Public License v3.0
from Aghoreshwar

    def __init__(self, varname=None, path=None):
        if path is None:
            raise template.TemplateSyntaxError(
                "Static template nodes must be given a path to return.")
        self.path = path
        self.varname = varname

    def url(self, context):

3 Source : tz.py
with GNU General Public License v3.0
from Aghoreshwar

def get_current_timezone_tag(parser, token):
    """
    Store the name of the current time zone in the context.

    Usage::

        {% get_current_timezone as TIME_ZONE %}

    This will fetch the currently active time zone and put its name
    into the ``TIME_ZONE`` context variable.
    """
    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
    args = token.contents.split()
    if len(args) != 3 or args[1] != 'as':
        raise TemplateSyntaxError("'get_current_timezone' requires "
                                  "'as variable' (got %r)" % args)
    return GetCurrentTimezoneNode(args[2])

3 Source : jinja2.py
with MIT License
from Air-999

    def render(self, context=None, request=None):
        from .utils import csrf_input_lazy, csrf_token_lazy
        if context is None:
            context = {}
        if request is not None:
            context['request'] = request
            context['csrf_input'] = csrf_input_lazy(request)
            context['csrf_token'] = csrf_token_lazy(request)
            for context_processor in self.backend.template_context_processors:
                context.update(context_processor(request))
        try:
            return self.template.render(context)
        except jinja2.TemplateSyntaxError as exc:
            new = TemplateSyntaxError(exc.args)
            new.template_debug = get_exception_info(exc)
            raise new from exc


class Origin:

3 Source : i18n.py
with MIT License
from Air-999

def do_get_current_language(parser, token):
    """
    Store the current language in the context.

    Usage::

        {% get_current_language as language %}

    This fetches the currently active language and puts its value into the
    ``language`` context variable.
    """
    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
    args = token.contents.split()
    if len(args) != 3 or args[1] != 'as':
        raise TemplateSyntaxError("'get_current_language' requires 'as variable' (got %r)" % args)
    return GetCurrentLanguageNode(args[2])


@register.tag("get_current_language_bidi")

3 Source : i18n.py
with MIT License
from Air-999

def language(parser, token):
    """
    Enable the given language just for this block.

    Usage::

        {% language "de" %}
            This is {{ bar }} and {{ boo }}.
        {% endlanguage %}
    """
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes one argument (language)" % bits[0])
    language = parser.compile_filter(bits[1])
    nodelist = parser.parse(('endlanguage',))
    parser.delete_first_token()
    return LanguageNode(nodelist, language)

3 Source : reviews.py
with MIT License
from andreynovikov

    def lookup_content_type(token, tagname):
        try:
            app, model = token.split('.')
            return ContentType.objects.get_by_natural_key(app, model)
        except ValueError:
            raise template.TemplateSyntaxError("Third argument in %r must be in the format 'app.model'" % tagname)
        except ContentType.DoesNotExist:
            raise template.TemplateSyntaxError("%r tag has non-existant content-type: '%s.%s'" % (tagname, app, model))

    def __init__(self, ctype=None, object_pk_expr=None, object_expr=None, as_varname=None, review=None):

3 Source : reviews.py
with MIT License
from andreynovikov

    def __init__(self, ctype=None, object_pk_expr=None, object_expr=None, as_varname=None, review=None):
        if ctype is None and object_expr is None:
            raise template.TemplateSyntaxError(
                "Review nodes must be given either a literal object or a ctype and object pk.")
        self.review_model = get_review_model()
        self.as_varname = as_varname
        self.ctype = ctype
        self.object_pk_expr = object_pk_expr
        self.object_expr = object_expr
        self.review = review
        self.filter_public = True

    def render(self, context):

3 Source : reviews.py
with MIT License
from andreynovikov

    def handle_token(cls, parser, token):
        """Class method to parse render_review_form and return a Node."""
        tokens = token.split_contents()
        if tokens[1] != 'for':
            raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])

        # {% render_review_form for obj %}
        if len(tokens) == 3:
            return cls(object_expr=parser.compile_filter(tokens[2]))

        # {% render_review_form for app.models pk %}
        elif len(tokens) == 4:
            return cls(
                ctype=BaseReviewNode.lookup_content_type(tokens[2], tokens[0]),
                object_pk_expr=parser.compile_filter(tokens[3])
            )

    def render(self, context):

3 Source : reviews.py
with MIT License
from andreynovikov

    def handle_token(cls, parser, token):
        """Class method to parse render_review_list and return a Node."""
        tokens = token.split_contents()
        if tokens[1] != 'for':
            raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])

        # {% render_review_list for obj %}
        if len(tokens) == 3:
            return cls(object_expr=parser.compile_filter(tokens[2]))

        # {% render_review_list for app.models pk %}
        elif len(tokens) == 4:
            return cls(
                ctype=BaseReviewNode.lookup_content_type(tokens[2], tokens[0]),
                object_pk_expr=parser.compile_filter(tokens[3])
            )

    def render(self, context):

3 Source : reviews.py
with MIT License
from andreynovikov

    def handle_token(cls, parser, token):
        """Class method to parse render_rating and return a Node."""
        tokens = token.split_contents()
        if tokens[1] != 'for':
            raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])

        # {% render_rating for obj %}
        if len(tokens) == 3:
            return cls(object_expr=parser.compile_filter(tokens[2]))

        # {% render_rating for app.models pk %}
        elif len(tokens) == 4:
            return cls(
                ctype=BaseReviewNode.lookup_content_type(tokens[2], tokens[0]),
                object_pk_expr=parser.compile_filter(tokens[3])
            )

    def render(self, context):

3 Source : jinja2.py
with MIT License
from chunky2808

    def get_template(self, template_name):
        try:
            return Template(self.env.get_template(template_name), self)
        except jinja2.TemplateNotFound as exc:
            six.reraise(
                TemplateDoesNotExist,
                TemplateDoesNotExist(exc.name, backend=self),
                sys.exc_info()[2],
            )
        except jinja2.TemplateSyntaxError as exc:
            new = TemplateSyntaxError(exc.args)
            new.template_debug = get_exception_info(exc)
            six.reraise(TemplateSyntaxError, new, sys.exc_info()[2])

    @cached_property

3 Source : tz.py
with MIT License
from chunky2808

def get_current_timezone_tag(parser, token):
    """
    Stores the name of the current time zone in the context.

    Usage::

        {% get_current_timezone as TIME_ZONE %}

    This will fetch the currently active time zone and put its name
    into the ``TIME_ZONE`` context variable.
    """
    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
    args = token.contents.split()
    if len(args) != 3 or args[1] != 'as':
        raise TemplateSyntaxError("'get_current_timezone' requires "
                                  "'as variable' (got %r)" % args)
    return GetCurrentTimezoneNode(args[2])

3 Source : snippet.py
with Apache License 2.0
from dockerizeme

def gravatar_url(parser, token):
    try:
        token_parts = token.split_contents()
        args = token_parts[1:]
    except ValueError, IndexError:
        raise template.TemplateSyntaxError, "%r tag requires at least one argument" % token.contents.split()[0]
    return GravatarUrlNode(*args)


class GravatarUrlNode(template.Node):

3 Source : snippet.py
with Apache License 2.0
from dockerizeme

def do_captureas(parser, token):

    try:
        tag_name, args = token.contents.split(None, 1)
    except ValueError:
        raise template.TemplateSyntaxError("'captureas' node requires a variable name.")

    nodelist = parser.parse(('endcaptureas',))
    parser.delete_first_token()

    return CaptureasNode(nodelist, args)


class CaptureasNode(template.Node):

3 Source : snippet.py
with Apache License 2.0
from dockerizeme

def do_straight_include(parser, token):
    """
    Loads a template and includes it without processing it
    
    Example::
    
    {% straight_include "foo/some_include" %}
    
    """
    bits = token.split_contents()
    if len(bits) != 2:
        raise template.TemplateSyntaxError("%r tag takes one argument: the location of the file within the template folder" % bits[0])
    path = bits[1][1:-1]
    
    return StraightIncludeNode(path)


register.tag("straight_include", do_straight_include)

3 Source : display_tags.py
with GNU General Public License v3.0
from foonsun

def get_parameters(parser, token):
    """
    {% get_parameters except_field %}
    """

    args = token.split_contents()
    if len(args)   <   2:
        raise template.TemplateSyntaxError(
            "get_parameters tag takes at least 1 argument")
    return GetParametersNode(args[1].strip())


class GetParametersNode(template.Node):

3 Source : display_tags.py
with GNU General Public License v3.0
from foonsun

def iffeature(parser, token):
    nodelist = parser.parse(('endiffeature',))
    try:
        tag_name, app_name, = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError(
            "%r tag requires a single argument" % token.contents.split()[0])
    if not (app_name[0] == app_name[-1] and app_name[0] in ('"', "'")):
        raise template.TemplateSyntaxError(
            "%r tag's argument should be in quotes" % tag_name)
    parser.delete_first_token()
    return ConditionalOutputNode(nodelist, app_name[1:-1])


class ConditionalOutputNode(template.Node):

3 Source : form_tags.py
with GNU General Public License v3.0
from foonsun

def annotate_form_field(parser, token):
    """
    Set an attribute on a form field with the widget type

    This means templates can use the widget type to render things differently
    if they want to.  Django doesn't make this available by default.
    """
    args = token.split_contents()
    if len(args)   <   2:
        raise template.TemplateSyntaxError(
            "annotate_form_field tag requires a form field to be passed")
    return FormFieldNode(args[1])


class FormFieldNode(template.Node):

3 Source : image_tags.py
with GNU General Public License v3.0
from foonsun

def do_dynamic_image_url(parser, token):
    tokens = token.split_contents()

    if len(tokens)   <   2:
        raise template.TemplateSyntaxError(
            "%r tag requires at least an image URL or field" % tokens[0])

    image = tokens[1]

    if len(tokens) > 2:
        params = tokens[2:]
    else:
        params = []
    return DynamicImageNode(image, params)


class DynamicImageNode(template.Node):

3 Source : sorting_tags.py
with GNU General Public License v3.0
from foonsun

def anchor(parser, token):
    bits = token.split_contents()
    if len(bits)   <   2:
        raise template.TemplateSyntaxError(
            "anchor tag takes at least 1 argument")
    try:
        title = bits[2]
    except IndexError:
        title = bits[1].capitalize()
    return SortAnchorNode(bits[1].strip(), title.strip())


class SortAnchorNode(template.Node):

3 Source : wishlist_tags.py
with GNU General Public License v3.0
from foonsun

def do_basket_form(parse, token):
    """
    Template tag for adding the user's wishlists form to the
    template context so it can be rendered.
    """
    tokens = token.split_contents()
    if len(tokens) != 5:
        raise template.TemplateSyntaxError(
            "%r tag uses the following syntax: "
            "{%% wishlists_containing_product wishlists product as "
            "ctx_var %%}" % tokens[0])

    wishlists_var, product_var, name_var = tokens[1], tokens[2], tokens[4]
    return ProductWishlistsNode(
        wishlists_var, product_var, name_var)


class ProductWishlistsNode(template.Node):

3 Source : idplist.py
with Apache License 2.0
from gethue

def idplist(parser, token):
    try:
        tag_name, as_part, variable = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError(
            '%r tag requires two arguments' % token.contents.split()[0])
    if not as_part == 'as':
        raise template.TemplateSyntaxError(
            '%r tag first argument must be the literal "as"' % tag_name)

    return IdPListNode(variable)

3 Source : agenda_custom_tags.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools

def agenda_anchor(parser, token):
    """Block tag that wraps its content in a link to the session agenda, if any"""
    try:
        tag_name, sess_var = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError('agenda_anchor requires a single argument')
    nodelist = parser.parse(('end_agenda_anchor',))
    parser.delete_first_token()  # delete the end tag
    return AgendaAnchorNode(sess_var, nodelist)


class LocationAnchorNode(AnchorNode):

3 Source : agenda_custom_tags.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools

def location_anchor(parser, token):
    """Block tag that wraps its content in a link to the timeslot location

    If the timeslot has no location information or is marked with show_location=False,
    the anchor tag is omitted.
    """
    try:
        tag_name, ts_var = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError('location_anchor requires a single argument')
    nodelist = parser.parse(('end_location_anchor',))
    parser.delete_first_token()  # delete the end tag
    return LocationAnchorNode(ts_var, nodelist)

3 Source : archive_extras.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools

def easy_tag(func):
    """deal with the repetitive parts of parsing template tags"""
    def inner(parser, token):
        try:
            return func(*token.split_contents())
        except TypeError:
            raise template.TemplateSyntaxError('Bad arguments for tag "%s"' % token.split_contents()[0])
    inner.__name__ = func.__name__
    inner.__doc__ = inner.__doc__
    return inner


# --------------------------------------------------
# Tags
# --------------------------------------------------


@register.tag()

3 Source : wtm_tags.py
with BSD 3-Clause "New" or "Revised" License
from jberghoef

    def __init__(self, nodelist, tag_type, src):
        if not tag_type:
            raise template.TemplateSyntaxError(_("Provide a `tag_type` argument."))

        self.nodelist = nodelist
        self.tag_type = tag_type.replace('"', "")
        self.src = src.replace('"', "")

    def render(self, context):

3 Source : test_templatetags_utils.py
with MIT License
from kiwicom

def test_templatestags_utils__singleton__wrong_identifier(identifier):
    with pytest.raises(template.TemplateSyntaxError):
        uut.singleton(identifier)


@pytest.mark.parametrize(

3 Source : find_tags.py
with MIT License
from knipknap

def find(parser, token):
    contents = token.split_contents()
    if len(contents)   <   2:
        raise template.TemplateSyntaxError(
            "%r tag requires at least 1 argument, " +
            "in the form of {%% %r model.objects.all [alias1 alias2 ...] %%}" % contents[0])

    return SearchNode(contents[1], contents[2:])

register = template.Library()

3 Source : tableheader.py
with Apache License 2.0
from ldv-klever

def tableheader(parser, token):
    try:
        tag_name, columns, titles = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError('%r tag requires exactly two arguments: '
                                           'list of columns and its titles' % token.contents.split()[0])
    return TableHeader(parser.compile_filter(columns), parser.compile_filter(titles))

3 Source : tree.py
with Apache License 2.0
from ldv-klever

def tree(parser, token):
    try:
        tag_name, tree_items, parent_attr, ordering_attr, icon_class = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError('%r tag requires exactly four arguments: '
                                           'dict of items, parent attribute, '
                                           'ordering attribute and icon class' % token.contents.split()[0])
    node_list = parser.parse('end' + tag_name)
    parser.delete_first_token()
    return TreeNode(
        node_list,
        parser.compile_filter(tree_items),
        parent_attr[1:-1],
        ordering_attr[1:-1],
        icon_class[1:-1]
    )

3 Source : comments.py
with Apache License 2.0
from lumanjiao

    def lookup_content_type(token, tagname):
        try:
            app, model = token.split('.')
            return ContentType.objects.get_by_natural_key(app, model)
        except ValueError:
            raise template.TemplateSyntaxError("Third argument in %r must be in the format 'app.model'" % tagname)
        except ContentType.DoesNotExist:
            raise template.TemplateSyntaxError("%r tag has non-existant content-type: '%s.%s'" % (tagname, app, model))

    def __init__(self, ctype=None, object_pk_expr=None, object_expr=None, as_varname=None, comment=None):

3 Source : comments.py
with Apache License 2.0
from lumanjiao

    def __init__(self, ctype=None, object_pk_expr=None, object_expr=None, as_varname=None, comment=None):
        if ctype is None and object_expr is None:
            raise template.TemplateSyntaxError("Comment nodes must be given either a literal object or a ctype and object pk.")
        self.comment_model = comments.get_model()
        self.as_varname = as_varname
        self.ctype = ctype
        self.object_pk_expr = object_pk_expr
        self.object_expr = object_expr
        self.comment = comment

    def render(self, context):

3 Source : comments.py
with Apache License 2.0
from lumanjiao

    def handle_token(cls, parser, token):
        """Class method to parse render_comment_form and return a Node."""
        tokens = token.split_contents()
        if tokens[1] != 'for':
            raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])

        # {% render_comment_form for obj %}
        if len(tokens) == 3:
            return cls(object_expr=parser.compile_filter(tokens[2]))

        # {% render_comment_form for app.models pk %}
        elif len(tokens) == 4:
            return cls(
                ctype = BaseCommentNode.lookup_content_type(tokens[2], tokens[0]),
                object_pk_expr = parser.compile_filter(tokens[3])
            )

    def render(self, context):

3 Source : comments.py
with Apache License 2.0
from lumanjiao

    def handle_token(cls, parser, token):
        """Class method to parse render_comment_list and return a Node."""
        tokens = token.split_contents()
        if tokens[1] != 'for':
            raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])

        # {% render_comment_list for obj %}
        if len(tokens) == 3:
            return cls(object_expr=parser.compile_filter(tokens[2]))

        # {% render_comment_list for app.models pk %}
        elif len(tokens) == 4:
            return cls(
                ctype = BaseCommentNode.lookup_content_type(tokens[2], tokens[0]),
                object_pk_expr = parser.compile_filter(tokens[3])
            )

    def render(self, context):

3 Source : cache.py
with Apache License 2.0
from lumanjiao

    def render(self, context):
        try:
            expire_time = self.expire_time_var.resolve(context)
        except VariableDoesNotExist:
            raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var)
        try:
            expire_time = int(expire_time)
        except (ValueError, TypeError):
            raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
        vary_on = [var.resolve(context) for var in self.vary_on]
        cache_key = make_template_fragment_key(self.fragment_name, vary_on)
        value = cache.get(cache_key)
        if value is None:
            value = self.nodelist.render(context)
            cache.set(cache_key, value, expire_time)
        return value

@register.tag('cache')

3 Source : i18n.py
with Apache License 2.0
from lumanjiao

def do_get_language_info(parser, token):
    """
    This will store the language information dictionary for the given language
    code in a context variable.

    Usage::

        {% get_language_info for LANGUAGE_CODE as l %}
        {{ l.code }}
        {{ l.name }}
        {{ l.name_local }}
        {{ l.bidi|yesno:"bi-directional,uni-directional" }}
    """
    args = token.split_contents()
    if len(args) != 5 or args[1] != 'for' or args[3] != 'as':
        raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:]))
    return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])

@register.tag("get_language_info_list")

3 Source : i18n.py
with Apache License 2.0
from lumanjiao

def do_get_current_language(parser, token):
    """
    This will store the current language in the context.

    Usage::

        {% get_current_language as language %}

    This will fetch the currently active language and
    put it's value into the ``language`` context
    variable.
    """
    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
    args = token.contents.split()
    if len(args) != 3 or args[1] != 'as':
        raise TemplateSyntaxError("'get_current_language' requires 'as variable' (got %r)" % args)
    return GetCurrentLanguageNode(args[2])

@register.tag("get_current_language_bidi")

3 Source : i18n.py
with Apache License 2.0
from lumanjiao

def do_get_current_language_bidi(parser, token):
    """
    This will store the current language layout in the context.

    Usage::

        {% get_current_language_bidi as bidi %}

    This will fetch the currently active language's layout and
    put it's value into the ``bidi`` context variable.
    True indicates right-to-left layout, otherwise left-to-right
    """
    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
    args = token.contents.split()
    if len(args) != 3 or args[1] != 'as':
        raise TemplateSyntaxError("'get_current_language_bidi' requires 'as variable' (got %r)" % args)
    return GetCurrentLanguageBidiNode(args[2])

@register.tag("trans")

3 Source : i18n.py
with Apache License 2.0
from lumanjiao

def language(parser, token):
    """
    This will enable the given language just for this block.

    Usage::

        {% language "de" %}
            This is {{ bar }} and {{ boo }}.
        {% endlanguage %}

    """
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes one argument (language)" % bits[0])
    language = parser.compile_filter(bits[1])
    nodelist = parser.parse(('endlanguage',))
    parser.delete_first_token()
    return LanguageNode(nodelist, language)

3 Source : tests.py
with Apache License 2.0
from lumanjiao

    def test_url_explicit_exception_for_old_syntax_at_compile_time(self):
        # Regression test for #19392
        with six.assertRaisesRegex(self, template.TemplateSyntaxError,
                "The syntax of 'url' changed in Django 1.5, see the docs."):
            t = Template('{% url my-view %}')      # not a variable = old syntax

    @override_settings(DEBUG=True, TEMPLATE_DEBUG=True)

3 Source : tests.py
with Apache License 2.0
from lumanjiao

    def test_load_error(self):
        ttext = "{% load broken_tag %}"
        self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
        try:
            template.Template(ttext)
        except template.TemplateSyntaxError as e:
            self.assertTrue('ImportError' in e.args[0])
            self.assertTrue('Xtemplate' in e.args[0])

    def test_load_error_egg(self):

3 Source : tests.py
with Apache License 2.0
from lumanjiao

    def test_load_error_egg(self):
        ttext = "{% load broken_egg %}"
        egg_name = '%s/tagsegg.egg' % self.egg_dir
        sys.path.append(egg_name)
        settings.INSTALLED_APPS = ('tagsegg',)
        self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
        try:
            template.Template(ttext)
        except template.TemplateSyntaxError as e:
            self.assertTrue('ImportError' in e.args[0])
            self.assertTrue('Xtemplate' in e.args[0])

    def test_load_working_egg(self):

3 Source : test_custom.py
with Apache License 2.0
from lumanjiao

    def test_simple_tag_missing_context(self):
        # The 'context' parameter must be present when takes_context is True
        six.assertRaisesRegex(self, template.TemplateSyntaxError,
            "'simple_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
            template.Template, '{% load custom %}{% simple_tag_without_context_parameter 123 %}')

    def test_inclusion_tags(self):

3 Source : test_custom.py
with Apache License 2.0
from lumanjiao

    def test_include_tag_missing_context(self):
        # The 'context' parameter must be present when takes_context is True
        six.assertRaisesRegex(self, template.TemplateSyntaxError,
            "'inclusion_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
            template.Template, '{% load custom %}{% inclusion_tag_without_context_parameter 123 %}')

    def test_inclusion_tags_from_template(self):

3 Source : mark_current.py
with MIT License
from matthiask

def do_mark_current(parser, token):
    try:
        tag_name, url_variable = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError(
            "%r tag requires one argument" % token.contents.split()[0]
        )

    nodelist = parser.parse(("endmark_current",))
    parser.delete_first_token()
    return MarkCurrentNode(nodelist, url_variable)


class MarkCurrentNode(template.Node):

See More Examples