Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:22:46+00:00 2026-05-31T18:22:46+00:00

I’m trying to implement some custom template tags to to a little more with

  • 0

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 & it still doesn’t work.

I’ve tried to follow this and current_time to implement some tags but I’m getting errors which I don’t understand.

First off, the filter of latest posts, or in my case latest screens gives
Exception Value: No module named gallery

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.

My custom tag code looks like this;

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)

I try to load that in the template using {% load get_latest gallery.screenshots 5 as recent_screens %} 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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:22:47+00:00Added an answer on May 31, 2026 at 6:22 pm

    The {% load %} template tag is used to load your custom template tag, not render it. If your get_latest tag is defined in a module my_tags.py, then you should load it using

    {% load my_tags %}
    

    See the code layout section of the docs for more information.

    Once you’ve loaded the tag in your template, then you can use it:

    {% get_latest gallery.screenshots 5 as recent_screens %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.