How do I get the class of a object within a Django template?

后端 未结 4 584
夕颜
夕颜 2021-02-12 16:58

If I have a list of objects that require similar layouts but need some attribute set based on the class of object how can I go about getting the class name while class

4条回答
  •  囚心锁ツ
    2021-02-12 17:26

    David's suggestion of a custom filter is great if you need this for several classes.

    The Django docs neglect to mention that the dev server won't detect new templatetags automatically, however, so until I restarted it by hand I was stuck with a TemplateSyntaxError class_tag is not a registered tag library.

    .

提交回复
热议问题