Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ademkocamaz/8886832618f28fd81c5e04747a367f28 to your computer and use it in GitHub Desktop.
Save ademkocamaz/8886832618f28fd81c5e04747a367f28 to your computer and use it in GitHub Desktop.
Custom django template tag that returns the verbose name of a field.
from django.template import Library
register = Library()
@register.simple_tag
def get_field_verbose_name(instance, field_name):
"""Returns the verbose_name of the specified field."""
return instance._meta.get_field(field_name).verbose_name.title()
{% load get_field_verbose_name %}
<!-- Will display the verbose_name and the value of the field -->
<p>{% get_field_verbose_name object 'my_field' %}: {{ object.my_field }}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment