IsInstance在Django模板中? [英] IsInstance in Django template?
问题描述
我希望显示两个不同的标记段,这取决于我在我的集合中迭代显示的项目类型。谢谢!
如果所有这些都继承自常见的基本类型,但是您需要知道它是哪种类型,想要在基础上实现一个返回类型的方法,那么你可以调用,如果foo.get_type =='type1'
(或任何)你的模板。 p>
Is there a way to do isinstance/issubclass in a Django template? I realise I can write my own templatetag, but I'm surprised this isn't possibly which makes me think I'm either doing something wrong or missing something obvious.
I wish to display two different segments of markup, depending on which type of item I'm displaying whilst iterative over my collection. Thanks!
If all of these inherit from a common base type, but you need to know which type it is, you may want to just implement a method on the base that returns the type - then you can call if foo.get_type == 'type1'
(or whatever) in your template.
这篇关于IsInstance在Django模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!