1

I'm working on an Inclusion Tag. In the super shell, the tag returns the appropiate data set nevertheles, I dont see the inclusion template rendered on the calling template. I can only guess the inclusion template is in the wrong location. As of this moment, the template is at MYPROJECT/templates which is the ONLY folder in TEMPLATE_DIRS. Please help me figure out what am I doing wrong here. TIA!

MYPROJECT/newsroom/templatetags/blog_extras.py -> http://pastebin.com/ssuLuVUq

from mezzanine.blog.models import BlogPost
from django import template

register = template.Library()

@register.inclusion_tag('featured_posts.html')
def featured_posts_list():
    """
    Return a set of blog posts whose featured_post=True.
    """

    blog_posts = BlogPost.objects.published().select_related("user")
    blog_posts = blog_posts.filter(featured_post=True)

    # import pdb; pdb.set_trace()
    return {'featured_posts_list': blog_posts}

MYPROJECT/templates/featured_posts.html -> http://pastebin.com/svyveqq3

{% load blog_tags keyword_tags i18n future %}

Meant to be the the infamous "Featured Posts" Section!
{{ featured_posts_list.count }}
<ul>
    {% for featured_post in featured_posts_list %}
        <li> {{ featured_post.title }} </li>
    {% endfor %}
</ul>

MYPROJECT/settings.py -> pastebin.com/Ed53qp5z

MYPROJECT/templates/blog/blog_post_list.html -> pastebin.com/tJedXjnT

4

1 回答 1

2

As @Victor Castillo Torres said, you need to change the name of the tag you're loading, which will fix that aspect of your template tag. However, even though they are in different namespaces, I would still change the name of the context variable your tag returns just for sanity:

@register.inclusion_tag('featured_posts.html')
def featured_posts_list():
    blog_posts = BlogPost.objects.published().filter(
        featured_post=True).select_related("user")
    return {'blog_posts': blog_posts}

Then in your template:

{{ blog_posts.count }}
<ul>
    {% for blog_post in blog_posts %}
        <li>{{ blog_post.title }} </li>
    {% endfor %}
</ul>

And finally, in your main template:

{% load blog_extras keyword_tags i18n_future %}
...
{% featured_posts_list %}
于 2013-10-13T04:18:57.143 回答