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

  • SEARCH
  • Home
  • 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 3979300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:09:11+00:00 2026-05-20T05:09:11+00:00

Writing template tags isn’t easy in Django and involves lots of boilerplate code. What

  • 0

Writing template tags isn’t easy in Django and involves lots of boilerplate code.
What is the least painful way to do it?

  • Are there any libs for that?
  • Are there any tricks that doesn’t involve third-party apps?
  • What is your way to do it?

(I will make this post a community wiki once I figure how to do it.)

  • 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-20T05:09:11+00:00Added an answer on May 20, 2026 at 5:09 am

    There are some libs for that:

    • django-templatetag-sugar

      Used it before. Makes everythings simpler, but I couldn’t figure how to handle lots of optional arguments with it.

      Usage example::

      ''' {% example_tag for val as asvar %} '''
      
      @tag(register, [
          Constant("for"), Variable(),
          Optional([Constant("as"), Name()]),
          ])
      def example_tag(context, val, asvar=None):
          if asvar:
              context[asvar] = val
              return ""
          else:
              return val
      
    • django-tagcon, abandoned by original author

    • django-ttag, fork of django-tagcon

      These two look promising because of class-based approach and keyword arguments support (like {% output limit=some_limit|default:1 offset=profile.offset %})

      Example usage::

      class Welcome(ttag.Tag):
          ''' {% welcome current_user fallback "Hello, anonymous." %} '''
          user = ttag.Arg(positional=True)
          fallback = ttag.Arg(default='Hi!')
      
          def output(self, data)
              name = data['user'].get_full_name()
              if name:
                  return 'Hi, %s!' % name
              return data['fallback']
      

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gone through the (painful) process of writing a custom template tag for
I'm trying to write a custom inclusion_tag in django. Following the example on http://docs.djangoproject.com/en/dev/howto/custom-template-tags/
I'm currently writing a template for a django project and am a complete javascript
I am currently writing a few custom template tags but for some reason they
I'm writing a template class and at one point in my code would like
For a new project we're writing documentation about the Django template system. We use
I am writing a template for my first django website. I am passing a
I'm writing a vector template with a few specializations so that there are named
I'm writing a template in xslt with xpath 1.0 and need to access the
I am writing a template class which takes a floating-point-like type (float, double, decimal,

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.