In views.py I have the following:
def keyword_list(request, template="keywords/popular_keywords.html"):
templates = []
templates.append(template)
context = {"popular_keywords": _popular_keywords()}
return render(request, templates, context)
where _popular_keywords() is a function that returns a dictionary of keywords (map of string to array of strings). Trust me this dictionary is populated.
In popular_keywords.html I have this
<ul>
{% for category, keywords in popular_keywords.items %}
<li>
<div class="subtitle">{{ category }}</div>
<ul>
{% for keyword in keywords %}
<li><a href="{% url "matching_items_list" keyword %}">{{ keyword }}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Meanwhile in urls.py I have this:
urlpatterns = patterns("vidya.keywords.views",
url("^%stag/(?P<tag>.*)%s$" % _slashes, "matching_items_list",
name="matching_item_list_tag")
)
Finally, matching_items_list is in views.py and rips off some Mezzanine code as Stephen suggested:
def matching_items_list(request, tag=None, template="keywords/keyword_matched_list.html"):
settings.use_editable()
templates = []
blog_posts = BlogPost.objects.published(for_user=request.user)
if tag is not None:
tag = get_object_or_404(Keyword, slug=tag)
blog_posts = blog_posts.filter(keywords__in=tag.assignments.all())
prefetch = ("keywords__keyword")
blog_posts = blog_posts.select_related("user").prefetch_related(*prefetch)
blog_posts = paginate(blog_posts, request.GET.get("page", 1),
settings.BLOG_POST_PER_PAGE,
settings.MAX_PAGING_LINKS)
context = {"blog_posts": blog_posts, "tag": tag}
templates.append(template)
return render(request, templates, context)
After all this, when I try to add the content to the base.html template
{% include "keywords/popular_keywords.html" %}
I don't get an error, but I don't see the generated content. I just see the "Popular Topics" hardcoded HTML at the top of my popular_keywords.html template.
Can anyone tell me how I can be generating nothing? I presume there is something basic I am missing, so any pointers in the right direction are appreciated.
Thanks.