Suppose I have a model:
from django.db import models
class Test(models.Model):
name=models.CharField(max_length=255, verbose_name=u'custom name')
How do I get my model’s field’s verbose name in templates? The following doesn’t work:
{{ test_instance.name.verbose_name }}
I would very much appreciate the solution, something on lines as we do when using forms, using label attribute in template:
{{ form_field.label }}
You can use following python code for this
If you want to use this in template then it will be best to register template tag for this. Create a
templatetagsfolder inside your app containing two files (__init__.pyandverbose_names.py).Put following code inverbose_names.py:Now you can use this template tag in your template after loading the library like this:
You can read about
Custom template tagsin official django documentation.