Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble implementing custom template tags in Django
    primarykey
    data
    text
    <p>I'm trying to implement some custom template tags to to a little more with my app and structure it better. The annoying part is that I've followed a tutorial type post to get the code &amp; it still doesn't work.</p> <p>I've tried to follow <a href="http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/" rel="nofollow">this</a> and <a href="https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/" rel="nofollow">current_time</a> to implement some tags but I'm getting errors which I don't understand.</p> <p>First off, the filter of latest posts, or in my case latest screens gives <code>Exception Value: No module named gallery</code></p> <p>My project is called 'S3gallery', my app is called 'gallery' and my model is called 'screenshots'. The model arg of the tag says in the docs it takes app_name.Model_name which is what I give it, so I'm stuck on this.</p> <p>My custom tag code looks like this;</p> <pre><code>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_screens tag takes exactly three arguments" if bits[3] != 'as': raise TemplateSyntaxError, "second argument to the get_latest_screens tag must be 'as'" return LatestContentNode(bits[1], bits[2], bits[4]) get_latest = register.tag(get_latest) </code></pre> <p>I try to load that in the template using <code>{% load get_latest gallery.screenshots 5 as recent_screens %}</code> and the examples I've seen don't use 'load' in the tag but if I do that Django doesn't recognise the tag. Do I'm lost by that, but think I'm going to the right way. Any help on this would be greatly appreciated :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload