[Answered ]-Using an abc.ABC class object in a Django template: why Django tries to instantiate it?

2👍

By default if the django template engine detects that a variable you are using is a callable it will call it before accessing sub-attributes. This is convenient in cases where you want the results of a function (which django doesn’t allow you to explicitly call). If you’d rather not have a particular callable called in the django templates you can set the flag do_not_call_in_templates to True on your object. In your case you probably want to do this on your base class so every subclass has this attribute too.

TL;DR:
Set abc.ABC.do_not_call_in_templates = True

Full documentation on how the django template language treats variables and for more info on the do_not_call_in_templates flag consult the django documentation.

👤K J

Leave a comment