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?
精彩评论