[Fixed]-Reusable HTML component libraries in Django


Have you taken a look at inclusion tags? https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags

I believe that these would do exactly what you want, you can still specify parameters but you can just pass along a template to have it render really easily.


from django import template
register = template.Library()

def list_results(results):
    return {
        'results': results,
        'count': len(results),


Found {{ count }} results.<br>
{% for result in results %}
    <li>{{ result }}</li>
{% endfor %}


Use templatetags and html template… Then you can reuse that HTML template…


Leave a comment