On Fri, Apr 4, 2008 at 11:14 AM, Claudio Escudero <[EMAIL PROTECTED]>
wrote:
> Hi,
> I am having a problem creating tag, I do not know what I am forgetting
>
> You are showing that error here:
> TemplateSyntaxError at /home/
> Invalid block tag: 'current_time'
>
> somebody have any idea?
> =/
>
I do not see in your template where you {% load current_time %} before
trying to use the tag it registers. See:
http://www.djangoproject.com/documentation/templates/#custom-tag-and-filter-libraries
Karen
> I have the files
> ##################################################################
> #### Template (teste.html):
> {% current_time "%Y-%m-%d %I:%M %p" %}
>
> #### I created a model myapp ( myproject/myapp )
> #### view.py
> from django.shortcuts import render_to_response
>
> def home(request):
> return render_to_response('teste.html')
>
> #### I create directory and file
> (myproject/myapp/templatetags/current_time.py)
> import datetime
> from django.core import template
> from django.core.template import Context, loader
>
> register = template.Library()
>
> def do_current_time(parser, token):
> try:
> # split_contents() knows not to split quoted strings.
> tag_name, format_string = token.split_contents()
> except ValueError:
> msg = '%r tag requires a single argument' % token.contents[0]
> raise template.TemplateSyntaxError(msg)
> return CurrentTimeNode(format_string[1:-1])
>
> class CurrentTimeNode(template.Node):
>
> def __init__(self, format_string):
> self.format_string = format_string
>
> def render(self, context):
> now = datetime.datetime.now()
> return now.strftime(self.format_string)
>
> register.tag('current_time', do_current_time)
> #############################################################
>
> Only that.
>
> =/
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---