Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Matthew Crist

It was the quotes.

Thanks for the tips!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Rock


Hmmm... Here are some guesses:

If that return statement in render is a single doublequote instead of
2 singlequotes, then your code probably won't parse and, even if it
does,  get_latest certainly won't be found.

It seems to me like you need to coerce the string being assigned to
self.num as make it an int. (Better yet, put that logic in the parse
section.) However that is unlikely to be the cause of the error that
you are seeing.

You might want to try compiling the code by hand to make sure there
are no stray typos.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Matthew Crist
I've got that. Here's my directory structure:

-blog
  -templatetags
 -__init__.py
 -get_latest.py

On Sep 25, 11:39 pm, Rock <[EMAIL PROTECTED]> wrote:
> You need an empty __init.py__ in the directory or else the python
> files there will not be found.
>
> On Sep 25, 10:29 pm, Matthew Crist <[EMAIL PROTECTED]> wrote:
>
> > Here's my template:
>
> > {% load get_latest %}
> >  > "http://www.w3.org/TR/html4/loose.dtd;>
> > 
> >         
> >                 My Site - {%block pagetitle %}{% endblock %}
> >         
> >         
> >                 My Site
> >                 
> >                         
> >                                 home
> >                                 Blog
> >                                 Links
> >                                 About
> >                         
> >                 
> >                 
> >                         
> >                                 {% block title %}{% endblock %}
> >                                 {% block primary %}{% endblock %}
> >                         
> >                         
> >                                 Recent Entries:
> >                                 {% get_latest blog.Entry 5 as recent_posts 
> > %}
> >                             
> >                                 {% for obj in recent_posts %}
> >                                         
> >                                                 {{ obj.title}}
> >                                         
> >                                         {% endfor %}
> >                                 
> >                         
> >                 
> >         
> > 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-25 Thread Rock
You need an empty __init.py__ in the directory or else the python
files there will not be found.

On Sep 25, 10:29 pm, Matthew Crist <[EMAIL PROTECTED]> wrote:
> Here's my template:
>
> {% load get_latest %}
>  "http://www.w3.org/TR/html4/loose.dtd;>
> 
>         
>                 My Site - {%block pagetitle %}{% endblock %}
>         
>         
>                 My Site
>                 
>                         
>                                 home
>                                 Blog
>                                 Links
>                                 About
>                         
>                 
>                 
>                         
>                                 {% block title %}{% endblock %}
>                                 {% block primary %}{% endblock %}
>                         
>                         
>                                 Recent Entries:
>                                 {% get_latest blog.Entry 5 as recent_posts %}
>                             
>                                 {% for obj in recent_posts %}
>                                         
>                                                 {{ obj.title}}
>                                         
>                                         {% endfor %}
>                                 
>                         
>                 
>         
> 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-25 Thread Matthew Crist

Here's my template:

{% load get_latest %}



My Site - {%block pagetitle %}{% endblock %}


My Site


home
Blog
Links
About




{% block title %}{% endblock %}
{% block primary %}{% endblock %}


Recent Entries:
{% get_latest blog.Entry 5 as recent_posts %}

{% for obj in recent_posts %}

{{ obj.title}}

{% endfor %}





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-25 Thread R. Gorman

Post your template code as well.

R.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



'get_latest' is not a valid tag library

2008-09-25 Thread Matthew Crist

I am trying to figure out templatetags, and I keep getting the
following error:

'get_latest' is not a valid tag library: Could not load template
library from django.templatetags.get_latest, No module named
get_latest

I started with this guide: 
http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/

I have the file saved as "get_latest.py" in the "templatetags"
directory, which is in my "blog" app. I have set the blog app as an
installed app in the settings.

Here is the code that I am using:

from django.template import Library, Node
from django.db.models import get_model

register = Library()

class LatestContentNode(Node):
def __init__(self, model, num, varname):
self.num, self.varname = num, varname
self.model = get_model(*model.split('.'))

def render(self, context):
context[self.varname] = self.model._default_manager.all()
[:self.num]
return ''

def get_latest(parser, token):
bits = token.contents.split()
if len(bits) != 5:
raise TemplateSyntaxError, "get_latest tag takes exactly four
arguments"
if bits[3] != 'as':
raise TemplateSyntaxError, "third argument to get_latest tag
must be 'as'"
return LatestContentNode(bits[1], bits[2], bits[4])

get_latest = register.tag(get_latest)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---