I have created a custom inclusion tag in an app called "popular_keywords" that generates a collection of links that function like search queries. So for example, I would like this
<li><a href="{% url "matching_items" keyword=keyword %}">{{ keyword }}</a></li>
to generate
<li><a href="/search/?q=Cake}">Cake</a></li>
I have the tag working correctly in terms of generating most of the content, but the url generation leads to
NoReverseMatch at /
Reverse for 'matching_items' with arguments '()' and keyword arguments '{u'keyword': 'Cake'}' not found.
What's weird is I have pretty much borrowed all the Mezzanine code to make this work, and no one on the Django forum can figure out the problem.
In the popular_keywords app, I have this in views.py:
def matching_items_list(request, keyword=None, template="popular_keywords/keyword_matched_list.html"):
settings.use_editable()
templates = []
blog_posts = BlogPost.objects.published(for_user=request.user)
if keyword is not None:
keyword = get_object_or_404(Keyword, slug=keyword)
blog_posts = blog_posts.filter(keywords__in=keyword.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, "keyword": keyword}
templates.append(template)
return render(request, templates, context)
And this is urls.py
urlpatterns = patterns("apps.popular_keywords.views",
url("^%skeyword/(?P<keyword>.*)%s$" % _slashes, "matching_items_list",
name="matching_items")
)
These were modeled after Mezzanine code in blog_post_list and this url function in Mezzanine
url("^%stag/(?P<tag>.*)%s$" % _slashes, "blog_post_list",
name="blog_post_list_tag")
Yet my call to the url function is failing as described above. I am curious if there is some Mezzanine magic I need to add to accomplish correct URL generation.
Thanks.