How to get object from PK inside Django template?

前端 未结 5 1690
逝去的感伤
逝去的感伤 2021-02-07 10:38

Inside django template, I would like to get object\'s name using object\'s pk. For instance, given that I have pk of object from class A, I would like to do somethi

5条回答
  •  鱼传尺愫
    2021-02-07 10:42

    You can't do that in Django. From the docs:

    Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display.

提交回复
热议问题