Re: Help with templatetags

2008-07-04 Thread Malcolm Tredinnick


On Fri, 2008-07-04 at 08:44 -0700, [EMAIL PROTECTED] wrote:
> i setup a custom template tag for my index page called recent_news.
> 
> i tried to setup a second template tag for the page called
> more_news.py. the first is working as recent_news.py.
> 
> recent_news.py gets the more recent entry, i have more_news.py set to
> get 2-6. i have {% load more_news %} since the file is more_news.py,
> it's in the same directory as recent_news.py and is the same file as
> recent_news.py other than the limits in what query results are getting
> and i'm getting the TemplateSyntaxError that the 'more_news' is not a
> valid tag library. what's up?

"And then I thought I'd post the same thing I did a couple of days ago
to start a new thread, rather than following on from the old one." :-)

Basic debugging 101: work out what has changed, back up until things
work and then go forwards one step at a time.

You claim that more_news.py is the same as recent_news.py with the
exception of some limits. That means you should be able to remove (or
"move aside") the more_news.py file, edit recent_news.py to use the
limits from more_news.py and it should work, right? Verify that. Now you
know that the code itself works.

Then you can diff the recent_news.py and more_news.py files to make sure
that the *only* differences are the tag names and the limits. So now you
know what has changed. Then you can check that in your template the
*only* thing you have changed to switch from using the tags in
recent_news.py to more_news.py is the "{% load ... %}" template tag.

At this point, you've changed things one step at a time:
1. start from a known, working recent_news.py
2. change it to behave like you want the new tag to behave.
3. rename the file to its target name and change the tag name
4. change the templates to use the new tag name

Everything should still be working by that point. If it's not, you've
found the problem. If it is and there are differences with your original
more_news.py file, then you know what to investigate.

There is no limitation on having multiple files in a templatetags/
directory or anything. The problem is somewhere in your code or in your
template. So just work through things one step at a time until something
breaks and then work out what caused that.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Help with templatetags

2008-07-04 Thread mccomas . chris

Yeah I did.

I actually tested it on my development server, also on a production
server (actually restarted apache several different times)...

On Jul 4, 2:22 pm, Brian Luft <[EMAIL PROTECTED]> wrote:
> Have you tried restarting the development server?  I've noticed that
> Django seems to cache template tag definitions when it starts up and
> won't pick up changes.  They may have addressed this but I've gotten
> in the habit of just restarting the development server whenever I'm
> mucking around with custom template libraries.
>
> -Brian
>
> On Jul 4, 8:44 am, [EMAIL PROTECTED] wrote:
>
> > i setup a custom template tag for my index page called recent_news.
>
> > i tried to setup a second template tag for the page called
> > more_news.py. the first is working as recent_news.py.
>
> > recent_news.py gets the more recent entry, i have more_news.py set to
> > get 2-6. i have {% load more_news %} since the file is more_news.py,
> > it's in the same directory as recent_news.py and is the same file as
> > recent_news.py other than the limits in what query results are getting
> > and i'm getting the TemplateSyntaxError that the 'more_news' is not a
> > valid tag library. what's up?
>
> > here's the code:
>
> > TEMPLATE
> > {% load more_news %}
> > {% get_morenews_list %}
> > {% for news in more_news %}
> > {{ news.title }}
> > {% endfor %}
>
> > MORE_NEWS.PY
> > from myproject.site.models import Blog
> > from django.template import Library,Node
>
> > register = Library()
>
> > def build_morenews_list(parser, token):
>
> > return NewsObject()
>
> > class NewsObject(Node):
> > def render(self, context):
> > context['more_news'] = Blog.blog_live.all().order_by('-
> > pub_date')[2:6]
> > return ''
>
> > register.tag('get_morenews_list', build_morenews_list)
--~--~-~--~~~---~--~~
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: Help with templatetags

2008-07-04 Thread Brian Luft

Have you tried restarting the development server?  I've noticed that
Django seems to cache template tag definitions when it starts up and
won't pick up changes.  They may have addressed this but I've gotten
in the habit of just restarting the development server whenever I'm
mucking around with custom template libraries.

-Brian

On Jul 4, 8:44 am, [EMAIL PROTECTED] wrote:
> i setup a custom template tag for my index page called recent_news.
>
> i tried to setup a second template tag for the page called
> more_news.py. the first is working as recent_news.py.
>
> recent_news.py gets the more recent entry, i have more_news.py set to
> get 2-6. i have {% load more_news %} since the file is more_news.py,
> it's in the same directory as recent_news.py and is the same file as
> recent_news.py other than the limits in what query results are getting
> and i'm getting the TemplateSyntaxError that the 'more_news' is not a
> valid tag library. what's up?
>
> here's the code:
>
> TEMPLATE
> {% load more_news %}
> {% get_morenews_list %}
> {% for news in more_news %}
>         {{ news.title }}
> {% endfor %}
>
> MORE_NEWS.PY
> from myproject.site.models import Blog
> from django.template import Library,Node
>
> register = Library()
>
> def build_morenews_list(parser, token):
>
>     return NewsObject()
>
> class NewsObject(Node):
>     def render(self, context):
>         context['more_news'] = Blog.blog_live.all().order_by('-
> pub_date')[2:6]
>         return ''
>
> register.tag('get_morenews_list', build_morenews_list)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---