Is there any way to get the model name of any objects in django templates. Manually, we can try it by defining methods in models or using template tags... But is there any b
You cannot access the class name directly. Doing something like this:
{{ object.__class__ }}
will cause a TemplateSyntaxError: Variables and attributes may not begin with underscores
. Django doesn't let you access those sorts of attributes - Python conventions means they are hidden implementation details, not part of the object's API.
Create a template filter instead, and then you can use it as follows:
{{ object|model_name_filter }}
Creating filters is very easy: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/