Search code examples
pythondjangofavoritesdjango-tagging

What are some useful non-built-in Django tags?


I'm relatively new to Django and I'm trying to build up my toolbox for future projects. In my last project, when a built-in template tag didn't do quite what I needed, I would make a mangled mess of the template to shoe-horn in the feature. I later would find a template tag that would have saved me time and ugly code.

So what are some useful template tags that doesn't come built into Django?


Solution

  • I'll start.

    http://www.djangosnippets.org/snippets/1350/

    Smart {% if %} template tag

    If you've ever found yourself needing more than a test for True, this tag is for you. It supports equality, greater than, and less than operators.

    Simple Example

    {% block list-products %}
        {% if products|length > 12 %}
            <!-- Code for pagination -->
        {% endif %}
    
        <!-- Code for displaying 12 products on the page -->
    
    {% endblock %}