from django import template from django.shortcuts import render_to_response register = template.Library() register.tag('custom_text', do_custom_text) class CustomTextNode(template.Node): def __init__(self, format_string): self.format_string = format_string def render(self, context): return render_to_response('custom_text.html') def do_custom_text(parser, token): try: tag_name, format_string = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0] if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")): raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name return CustomTextNode(format_string[1:-1])