[Django]-Django – Python help_text as a clickable icon

3👍

You could create a templatetag, something along these lines should work (untested)

@register.simple_tag
def render_help_text(field):
    if hasattr(field, 'help_text'):
        return mark_safe(
            "<a><img src='/static/img/icons/help.gif' title='{help_text}' /></a>".format(**{'help_text': field.help_text})
        )
    return ''

template

{% for field in form %}
    <!-- other stuff -->
    {% render_help_text field %}
{% endfor %}

Leave a comment