Skip to content
Advertisement

Django – Template display model verbose_names & objects

I need to display several models name & objects in a template

Here is my view

JavaScript

And my template

JavaScript

Of course objs._meta.verbose_name doesn’t work

Is there a way to access to this verbose name without having to create a function for each model or to assign the value from the view for each model ?

Advertisement

Answer

For accessing it in your template, you’ve probably noticed by now that Django doesn’t let you use underscore prefixes to access attributes from templates. Thus, the easiest way to access the verbose name for any given object without having to create a model method on each model would be to just create a template tag:

JavaScript

Unrelated, but you have a bug in your template, in that you are trying to access the _meta attribute on a queryset instead of an object. So your title line should instead look something like:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement