當前位置: 首頁>>代碼示例>>Python>>正文


Python template.VariableDoesNotExist方法代碼示例

本文整理匯總了Python中django.template.VariableDoesNotExist方法的典型用法代碼示例。如果您正苦於以下問題:Python template.VariableDoesNotExist方法的具體用法?Python template.VariableDoesNotExist怎麽用?Python template.VariableDoesNotExist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.template的用法示例。


在下文中一共展示了template.VariableDoesNotExist方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            if '.' in self.field_var:
                base, field_name = self.field_var.rsplit('.', 1)
                field = getattr(Variable(base).resolve(context), field_name)
            else:
                field = context[self.field_var]
        except (template.VariableDoesNotExist, KeyError, AttributeError):
            return settings.TEMPLATE_STRING_IF_INVALID

        h_attrs = {}
        for k, v in iteritems(self.html_attrs):
            try:
                h_attrs[k] = v.resolve(context)
            except template.VariableDoesNotExist:
                h_attrs[k] = settings.TEMPLATE_STRING_IF_INVALID

        return field(**h_attrs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:20,代碼來源:wtforms.py

示例2: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            value = self.block_var.resolve(context)
        except template.VariableDoesNotExist:
            return ''

        if hasattr(value, 'render_as_block'):
            if self.use_parent_context:
                new_context = context.flatten()
            else:
                new_context = {}

            if self.extra_context:
                for var_name, var_value in self.extra_context.items():
                    new_context[var_name] = var_value.resolve(context)

            return value.render_as_block(context=new_context)
        else:
            return force_str(value) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:21,代碼來源:wagtailcore_tags.py

示例3: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            value = self.block_var.resolve(context)
        except template.VariableDoesNotExist:
            return ''

        if isinstance(value, dict): # its an preview
            code_renderer = CodeRenderer()
            bl_class = get_block_class_for(value.get('type', 'INVALID_PLUGIN_WITH_NO_TYPE'))
            if bl_class:
                instance = bl_class(value, code_renderer)
                return instance.render(context)
            else:
                return ''
        elif isinstance(value, str):
            try:
                value = HyperFieldResponse.from_str(value)
                return value.render(context)
            except Exception as e:
                print(e)
                return ''
        else:
            return value.render(context) 
開發者ID:DivineITLimited,項目名稱:django-hyper-editor,代碼行數:25,代碼來源:hyper_tags.py

示例4: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
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)
        # Build a key for this fragment and all vary-on's.
        key = ':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on])
        args = hashlib.md5(force_bytes(key))
        cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
        value = cache.get(cache_key)
        if value is None:
            value = self.nodelist.render(context)
            cache.set(cache_key, value, expire_time)
        return value 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:20,代碼來源:cache.py

示例5: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            user = self.user.resolve(context)
        except template.VariableDoesNotExist:
            return ""

        if not self.um_to_user:
            message_count = MessageRecipient.objects.count_unread_messages_for(user)

        else:
            try:
                um_to_user = self.um_to_user.resolve(context)
            except template.VariableDoesNotExist:
                return ""

            message_count = MessageRecipient.objects.count_unread_messages_between(
                user, um_to_user
            )

        context[self.var_name] = message_count

        return "" 
開發者ID:django-userena-ce,項目名稱:django-userena-ce,代碼行數:24,代碼來源:umessages_tags.py

示例6: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        if "." in self.manager_method:
            manager, method = self.manager_method.split(".")
        else:
            manager = "_default_manager"
            method = self.manager_method

        model_manager = getattr(self.model, manager)
        fallback_method = self.model._default_manager.none
        qs = getattr(model_manager, method, fallback_method)()
        limit = None
        if self.limit:
            try:
                limit = self.limit.resolve(context)
            except template.VariableDoesNotExist:
                limit = None
        context[self.var_name] = qs[:limit] if limit else qs
        return "" 
開發者ID:PacktPublishing,項目名稱:Django-2-Web-Development-Cookbook-Third-Edition,代碼行數:20,代碼來源:utility_tags.py

示例7: test_log_on_variable_does_not_exist_not_silent

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def test_log_on_variable_does_not_exist_not_silent(self):
        with self.assertLogs('django.template', self.loglevel) as cm:
            with self.assertRaises(VariableDoesNotExist):
                Variable('article.author').resolve({'article': {'section': 'News'}})

        self.assertEqual(len(cm.records), 1)
        log_record = cm.records[0]
        self.assertEqual(
            log_record.getMessage(),
            "Exception while resolving variable 'author' in template 'unknown'."
        )
        self.assertIsNotNone(log_record.exc_info)
        raised_exception = log_record.exc_info[1]
        self.assertEqual(
            str(raised_exception),
            "Failed lookup for key [author] in {'section': 'News'}"
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_logging.py

示例8: style_attribute

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def style_attribute(attribute_name, package):
    mappings = {
            'title': style_title,
            'repo_description': style_repo_description,
            'commits_over_52': style_commits,
    }

    as_var = template.Variable('package.' + attribute_name)
    try:
        value = as_var.resolve({'package': package})
    except template.VariableDoesNotExist:
        value = ''

    if attribute_name in list(mappings.keys()):
        return  mappings[attribute_name](value)

    return style_default(value) 
開發者ID:wise-team,項目名稱:steemprojects.com,代碼行數:19,代碼來源:grid_tags.py

示例9: takes_current_page

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def takes_current_page(func):
    """Decorator for template tags that require the current page."""

    @wraps(func)
    def do_takes_current_page(context, *args, **kwargs):
        page = get_page_from_context(context, kwargs)

        if not page:
            page = get_default_news_page()
        if page is None:
            raise template.VariableDoesNotExist("Could not determine the current page from the template context.")
        kwargs["page"] = page

        return func(context, *args, **kwargs)

    return do_takes_current_page 
開發者ID:rocket-league-replays,項目名稱:rocket-league-replays,代碼行數:18,代碼來源:news.py

示例10: tryresolve

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def tryresolve(var, context, default=None):
    try:
        return var.resolve(context)
    except template.VariableDoesNotExist:
        return default 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:7,代碼來源:donation_tags.py

示例11: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            time = self.time.resolve(context)
            try:
                now = datetime.datetime.now() - time
            except TypeError:
                return ''
            return '%d.%d seconds' % (now.seconds, now.microseconds)
        except template.VariableDoesNotExist:
            return '' 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:12,代碼來源:donation_tags.py

示例12: hash

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def hash(object, attr):
    pseudo_context = { 'object' : object }
    try:
        value = Variable('object.%s' % attr).resolve(pseudo_context)
    except VariableDoesNotExist:
        value = None
    return value 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:9,代碼來源:course_display.py

示例13: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            dictionary = self.dictionary.resolve(context)
            aslug = self.aslug.resolve(context)
            userid = self.userid.resolve(context)
        except template.VariableDoesNotExist:
            return "?"

        grades = dictionary[aslug]
        if userid not in grades:
            return ''

        grade = grades[userid]
        gtext = escape(grade.display_staff_short())

        stext = ''
        if grade.flag not in ['GRAD', 'NOGR', 'CALC']:
            stext = '(' + grade.get_flag_display() + ')'


        if grade.comment:
            ctext = escape(grade.comment)
            stext = '(' + grade.get_flag_display() + ')'
        else:
            ctext = ''
        
        if ctext and stext:
            return mark_safe(gtext + '<span class="more"><span title="' + ctext + '"><img src="/media/icons/information.png" alt="[I]" /></span><br/>' + stext + '</span>')
        elif stext:
            return mark_safe(gtext + '<span class="more"><br/>' + stext + '</span>')
        else:
            return mark_safe(gtext) 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:34,代碼來源:grade_student.py

示例14: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import VariableDoesNotExist [as 別名]
def render(self, context):
        try:
            self.value = self.value.resolve(context)
            if not isinstance(self.value, ImageFieldFile):
                raise template.VariableDoesNotExist(
                    'Image argument should be an ImageField')
            images = context.dicts[0].setdefault('ootemplate_imgs', {})

            id = len(images)
            z_index = id + 3  # Magic
            width = self.value.width * PIXEL_TO_CM
            height = self.value.height * PIXEL_TO_CM
            filename = os.path.basename(self.value.name)
            basename = os.path.splitext(filename)[0]

            images[self.value.path] = self.value
            return ('<draw:frame draw:style-name="gr%(z_index)s" '
                    'draw:name="%(basename)s" '
                    'draw:id="id%(id)s" '
                    'text:anchor-type="char" svg:width="%(width)fcm" '
                    'svg:height="%(height)fcm" draw:z-index="%(z_index)s">'
                    '<draw:image xlink:href="Pictures/%(filename)s" '
                    'xlink:type="simple" xlink:show="embed" '
                    'xlink:actuate="onLoad"/></draw:frame>') % locals()
        except template.VariableDoesNotExist:
            return '' 
開發者ID:alexmorozov,項目名稱:templated-docs,代碼行數:28,代碼來源:templated_docs_tags.py


注:本文中的django.template.VariableDoesNotExist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。