开发者

Django custom template tag problem

This is my python code for 'box':

register = Library()

class KeyNode(Node):
    def __init__(self,  _node):
        self._node = _node,

    def render(self, context):
        try:
            #content = "this works!"
            content = self._node.render(context)
            return content
        except:
            bilogger.exception('KeyNode')
            return ''

@register.tag('box')
def wrapper(parser, token):
   开发者_如何学运维 try:
        #fn, _option = token.split_contents()
        node = parser.parse(('endbox',))
        parser.delete_first_token() 
    except ValueError:
        raise TemplateSyntaxError("INVALID FORMAT PROVIDED FOR BOX")
    return KeyNode(node)

self._node.render(context) is an empty string, and nothing is returned back. However, content = "this works!", works.

Whats wrong here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜