Django template object type

后端 未结 2 482
无人及你
无人及你 2021-02-07 12:40

Alright, here\'s my situation. I\'ve got an array of generic objects that I\'m iterating over in a django template. Those objects have a number of subclasses and I want to fig

2条回答
  •  星月不相逢
    2021-02-07 13:27

    You'll have to do it via some sort of method. Why not just write a method like display_location() or something on the model itself and have it return the string which gets rendered there? Then you could just put {{ beer.display_location }} in your template.

    Or if you want to go really crazy, write a custom template tag that does what you want, but that's much more work.

提交回复
热议问题